From 63611daf7bd1daf59298cb8f67adebde7c12b9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20G=C3=B3mez?= Date: Tue, 16 May 2017 05:03:58 -0400 Subject: [PATCH] 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 --- .../main/kotlin/com/baeldung/kotlin/User.kt | 3 ++ .../com/baeldung/kotlin/EqualityTest.kt | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt diff --git a/kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt b/kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt new file mode 100644 index 0000000000..759627b56e --- /dev/null +++ b/kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt @@ -0,0 +1,3 @@ +package com.baeldung.kotlin + +data class User(val name: String, val age: Int, val hobbies: List) diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt index 7cf2faaf42..6fb6d0a288 100644 --- a/kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt @@ -23,4 +23,36 @@ class EqualityTest { 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) + } } \ No newline at end of file