@Test public void deepCopyMutateUtf8() { Nested n = new Nested(); Utf8 utf8 = new Utf8("Sample"); n.name = utf8; n.value = 12; Nested copy = new Nested(); RecordUtils.copy(n, copy); modify(n.name); n.value = null; // but our copies should NOT be affected assertEquals("Sample", copy.name.toString()); assertEquals(12, (int) copy.value); }
@Test public void deepCopyMutateList() { Gend in = new Gend(); in.collection = new ArrayList<Nested>(); Nested n1 = new Nested(); n1.name = new Utf8("one"); n1.value = 11; in.collection.add(n1); Nested n2 = new Nested(); n2.name = new Utf8("two"); in.collection.add(n2); Gend out = new Gend(); RecordUtils.copy(in, out); n1.name = null; modify(n2.name); in.collection.clear(); assertEquals(2, out.collection.size()); assertEquals("one", out.collection.get(0).name.toString()); assertEquals(11, (int) out.collection.get(0).value); assertNull(out.collection.get(1).value); }