have Event#toMap return copy

Fixes #5296
This commit is contained in:
Tal Levy 2016-05-13 09:48:43 -07:00
parent c6aaf58ff0
commit 7a1851ddc7
3 changed files with 12 additions and 2 deletions

View file

@ -189,7 +189,7 @@ public class Event implements Cloneable, Serializable {
}
public Map toMap() {
return this.data;
return Cloner.deep(this.data);
}
public Event overwrite(Event e) {

View file

@ -245,7 +245,7 @@ public class JrubyEventExtLibrary implements Library {
@JRubyMethod(name = "to_hash")
public IRubyObject ruby_to_hash(ThreadContext context) throws IOException
{
return Rubyfier.deep(context.runtime, this.event.toMap());
return Rubyfier.deep(context.runtime, this.event.getData());
}
@JRubyMethod(name = "to_hash_with_metadata")

View file

@ -4,6 +4,7 @@ import org.junit.Test;
import java.io.IOException;
import java.util.*;
import static org.junit.Assert.*;
import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
@ -104,6 +105,15 @@ public class EventTest {
assertJsonEquals(f.toJson(), e.toJson());
}
@Test
public void testToMap() throws Exception {
Event e = new Event();
Map original = e.getData();
Map clone = e.toMap();
assertFalse(original == clone);
assertEquals(original, clone);
}
@Test
public void testAppend() throws Exception {
Map data1 = new HashMap();