File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
core-kotlin-modules/core-kotlin-10/src/test/kotlin/com/baeldung/cloningobject Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,28 @@ class CloningObjectUnitTest {
149
149
.isNotEqualTo(" New Employee Address City Name" )
150
150
}
151
151
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
+
152
174
@Test
153
175
fun `when cloned object with copy() then proves that deep copy` () {
154
176
You can’t perform that action at this time.
0 commit comments