Feature/kotlin map examples (#2220)

* 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 Kotlin test to convert list to map

* Add additional associate methods on test for ListToMap file
This commit is contained in:
Walter Gómez 2017-07-07 01:03:37 -06:00 committed by Grzegorz Piwowarek
parent 5a184d4e0d
commit 2863d0c3e0
1 changed files with 39 additions and 0 deletions

View File

@ -8,6 +8,7 @@ class ListToMapTest {
val user1 = User("John", 18, listOf("Hiking, Swimming"))
val user2 = User("Sara", 25, listOf("Chess, Board Games"))
val user3 = User("Dave", 34, listOf("Games, Racing sports"))
val user4 = User("John", 30, listOf("Reading, Poker"))
@Test
fun givenList_whenConvertToMap_thenResult() {
@ -32,4 +33,42 @@ class ListToMapTest {
assertTrue(myMap.get("a") == "a")
}
@Test
fun givenStringList_whenAssociate_thenResult() {
val myList = listOf("a", "b", "c", "c", "b")
val myMap = myList.associate{ it to it }
assertTrue(myMap.get("a") == "a")
}
@Test
fun givenStringList_whenAssociateTo_thenResult() {
val myList = listOf("a", "b", "c", "c", "b")
val myMap = mutableMapOf<String, String>()
myList.associateTo(myMap) {it to it}
assertTrue(myMap.get("a") == "a")
}
@Test
fun givenStringList_whenAssociateByTo_thenResult() {
val myList = listOf(user1, user2, user3, user4)
val myMap = mutableMapOf<String, Int>()
myList.associateByTo(myMap, {it.name}, {it.age})
assertTrue(myMap.get("Dave") == 34)
}
@Test
fun givenStringList_whenAssociateByToUser_thenResult() {
val myList = listOf(user1, user2, user3, user4)
val myMap = mutableMapOf<String, User>()
myList.associateByTo(myMap) {it.name}
assertTrue(myMap.get("Dave")!!.age == 34)
}
}