Fix/kotlin equality (#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
This commit is contained in:
Walter Gómez 2017-05-16 05:03:58 -04:00 committed by Grzegorz Piwowarek
parent e2aabe819e
commit 63611daf7b
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,3 @@
package com.baeldung.kotlin
data class User(val name: String, val age: Int, val hobbies: List<String>)

View File

@ -23,4 +23,36 @@ class EqualityTest {
assertTrue(a == b) assertTrue(a == b)
} }
@Test
fun givenUser_whenCheckReference_thenEqualReference() {
val user = User("John", 30, listOf("Hiking, Chess"))
val user2 = User("Sarah", 28, listOf("Shopping, Gymnastics"))
assertFalse(user === user2)
}
@Test
fun givenUser_whenCheckValue_thenStructurallyEqual() {
val user = User("John", 30, listOf("Hiking, Chess"))
val user2 = User("John", 30, listOf("Hiking, Chess"))
assertTrue(user == user2)
}
@Test
fun givenArray_whenCheckReference_thenEqualReference() {
val hobbies = arrayOf("Riding motorcycle, Video games")
val hobbies2 = arrayOf("Riding motorcycle, Video games")
assertFalse(hobbies === hobbies2)
}
@Test
fun givenArray_whenCheckContent_thenStructurallyEqual() {
val hobbies = arrayOf("Hiking, Chess")
val hobbies2 = arrayOf("Hiking, Chess")
assertTrue(hobbies contentEquals hobbies2)
}
} }