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
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
+ }
You can’t perform that action at this time.
0 commit comments