Skip to content

Commit 63611da

Browse files
Walter Gómezpivovarit
authored andcommitted
Fix/kotlin equality (eugenp#1861)
* Add project for hibernate immutable article Add Event entity Add hibernate configuration file Add hibernateutil for configuration Add test to match snippets from article * Update master * Add simplet test to check Kotlin rerence vs strutural equality * Update README * Kotlin equality - fix Add suite of tests for complex object and arrays Add User class
1 parent e2aabe8 commit 63611da

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.baeldung.kotlin
2+
3+
data class User(val name: String, val age: Int, val hobbies: List<String>)

‎kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,36 @@ class EqualityTest {
2323

2424
assertTrue(a == b)
2525
}
26+
27+
@Test
28+
fun givenUser_whenCheckReference_thenEqualReference() {
29+
val user = User("John", 30, listOf("Hiking, Chess"))
30+
val user2 = User("Sarah", 28, listOf("Shopping, Gymnastics"))
31+
32+
assertFalse(user === user2)
33+
}
34+
35+
@Test
36+
fun givenUser_whenCheckValue_thenStructurallyEqual() {
37+
val user = User("John", 30, listOf("Hiking, Chess"))
38+
val user2 = User("John", 30, listOf("Hiking, Chess"))
39+
40+
assertTrue(user == user2)
41+
}
42+
43+
@Test
44+
fun givenArray_whenCheckReference_thenEqualReference() {
45+
val hobbies = arrayOf("Riding motorcycle, Video games")
46+
val hobbies2 = arrayOf("Riding motorcycle, Video games")
47+
48+
assertFalse(hobbies === hobbies2)
49+
}
50+
51+
@Test
52+
fun givenArray_whenCheckContent_thenStructurallyEqual() {
53+
val hobbies = arrayOf("Hiking, Chess")
54+
val hobbies2 = arrayOf("Hiking, Chess")
55+
56+
assertTrue(hobbies contentEquals hobbies2)
57+
}
2658
}

0 commit comments

Comments
 (0)