File tree Expand file tree Collapse file tree
core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/deepcopy Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments