Skip to content

Commit 5bd2f21

Browse files
committed
cloning object
1 parent f8e6535 commit 5bd2f21

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.cloningobject
2+
3+
import org.junit.jupiter.api.Assertions.*
4+
import org.junit.jupiter.api.Test
5+
class CloningObjectUnitTest {
6+
data class Person(val name: String, val address: Address)
7+
data class Address(val street: String, val city: String)
8+
9+
@Test
10+
fun `when copy an object then compare`(){
11+
val address = Address("Jalan Kemasan", "Yogyakarta")
12+
val firstPerson = Person("Hangga", address)
13+
val secondPerson = firstPerson.copy()
14+
15+
assertTrue(firstPerson == secondPerson)
16+
assertTrue(firstPerson.name == secondPerson.name)
17+
assertTrue(firstPerson.address === secondPerson.address)
18+
assertTrue(firstPerson.address.street == secondPerson.address.street)
19+
assertTrue(firstPerson.address.city == secondPerson.address.city)
20+
assertFalse(firstPerson === secondPerson)
21+
}
22+
}

0 commit comments

Comments
 (0)