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:
		
							parent
							
								
									e2aabe819e
								
							
						
					
					
						commit
						63611daf7b
					
				
							
								
								
									
										3
									
								
								kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| package com.baeldung.kotlin | ||||
| 
 | ||||
| data class User(val name: String, val age: Int, val hobbies: List<String>) | ||||
| @ -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) | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user