Skip to content

Commit bafce25

Browse files
committed
add shallow copy unit test
1 parent 7f9ba76 commit bafce25

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

core-kotlin-modules/core-kotlin-10/src/test/kotlin/com/baeldung/cloningobject/CloningObjectUnitTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ class CloningObjectUnitTest {
149149
.isNotEqualTo("New Employee Address City Name")
150150
}
151151

152+
@Test
153+
fun `when cloned object with copy() then proves that shallow copy`() {
154+
val clonedOrganization = organization.copy()
155+
156+
modifyOrganization()
157+
158+
assertThat(clonedOrganization)
159+
.isNotSameAs(organization)
160+
assertThat(clonedOrganization.headquarters.city)
161+
.isEqualTo("New City")
162+
assertThat(clonedOrganization.companies.first().name)
163+
.isEqualTo("New Company Name")
164+
assertThat(clonedOrganization.companies.first().ceo.name)
165+
.isEqualTo("New CEO Name")
166+
assertThat(clonedOrganization.companies.first().ceo.address.city)
167+
.isEqualTo("New CEO Address City Name")
168+
assertThat(clonedOrganization.companies.first().employees.first().name)
169+
.isEqualTo("New Employee Name")
170+
assertThat(clonedOrganization.companies.first().employees.first().address.city)
171+
.isEqualTo("New Employee Address City Name")
172+
}
173+
152174
@Test
153175
fun `when cloned object with copy() then proves that deep copy`() {
154176

0 commit comments

Comments
 (0)