Skip to content

Commit ec59a9c

Browse files
committed
[BAEL-16045] - Check Article Code Matches GitHub for https://www.baeldung.com/java-deep-copy article
1 parent c06471c commit ec59a9c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/deepcopy/DeepCopyUnitTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void whenCreatingDeepCopyWithCopyConstructor_thenObjectsShouldNotBeSame()
2525
}
2626

2727
@Test
28-
public void whenModifyingOriginalObject_thenConstructorCopyShouldNotChange() {
28+
public void whenModifyingOriginalObject_thenCopyShouldNotChange() {
2929
Address address = new Address("Downing St 10", "London", "England");
3030
User pm = new User("Prime", "Minister", address);
3131
User deepCopy = new User(pm);
@@ -125,4 +125,13 @@ public void whenMakingCopies_thenShowHowLongEachMethodTakes() throws CloneNotSup
125125
end = System.currentTimeMillis();
126126
System.out.println("Cloning with Jackson took " + (end - start) + " milliseconds.");
127127
}
128+
129+
@Test
130+
public void whenModifyingOriginalObject_ThenCopyShouldChange() {
131+
Address address = new Address("Downing St 10", "London", "England");
132+
User pm = new User("Prime", "Minister", address);
133+
User shallowCopy = new User(pm.getFirstName(), pm.getLastName(), pm.getAddress());
134+
address.setCountry("Great Britain");
135+
assertThat(shallowCopy.getAddress().getCountry()).isEqualTo(pm.getAddress().getCountry());
136+
}
128137
}

0 commit comments

Comments
 (0)