From 2863d0c3e0b873cb10a9fd8cba0fe1700509691b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20G=C3=B3mez?= Date: Fri, 7 Jul 2017 01:03:37 -0600 Subject: [PATCH] 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 --- .../com/baeldung/kotlin/ListToMapTest.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/ListToMapTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/ListToMapTest.kt index 6371b1da96..e3477931bb 100644 --- a/kotlin/src/test/kotlin/com/baeldung/kotlin/ListToMapTest.kt +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/ListToMapTest.kt @@ -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() + + 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() + + 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() + + myList.associateByTo(myMap) {it.name} + + assertTrue(myMap.get("Dave")!!.age == 34) + } } \ No newline at end of file