diff --git a/kotlin/pom.xml b/kotlin/pom.xml index b93d867f0a..59f71f91a6 100644 --- a/kotlin/pom.xml +++ b/kotlin/pom.xml @@ -14,6 +14,18 @@ kotlin-stdlib 1.0.4 + + org.jetbrains.kotlin + kotlin-test-junit + 1.0.4 + test + + + junit + junit + 4.12 + test + @@ -24,7 +36,6 @@ kotlin-maven-plugin org.jetbrains.kotlin 1.0.4 - compile diff --git a/kotlin/src/main/kotlin/com/baeldung/Item.kt b/kotlin/src/main/kotlin/com/baeldung/Item.kt new file mode 100644 index 0000000000..c0b6dd7631 --- /dev/null +++ b/kotlin/src/main/kotlin/com/baeldung/Item.kt @@ -0,0 +1,4 @@ +package com.baeldung + + +data class Item(val id: String, val name: String) \ No newline at end of file diff --git a/kotlin/src/main/kotlin/com/baeldung/ItemService.kt b/kotlin/src/main/kotlin/com/baeldung/ItemService.kt new file mode 100644 index 0000000000..7597e2aca6 --- /dev/null +++ b/kotlin/src/main/kotlin/com/baeldung/ItemService.kt @@ -0,0 +1,10 @@ +package com.baeldung + +import java.util.* + +class ItemService { + fun findItemNameForId(id: String): Item? { + val itemId = UUID.randomUUID().toString() + return Item(itemId, "name-$itemId"); + } +} \ No newline at end of file diff --git a/kotlin/src/test/kotlin/com/baeldung/ItemServiceTest.kt b/kotlin/src/test/kotlin/com/baeldung/ItemServiceTest.kt new file mode 100644 index 0000000000..2442cb18b2 --- /dev/null +++ b/kotlin/src/test/kotlin/com/baeldung/ItemServiceTest.kt @@ -0,0 +1,20 @@ +package com.baeldung + +import org.junit.Test +import kotlin.test.assertNotNull + +class ItemServiceTest { + @Test + fun givenItemId_whenGetForOptionalName_shouldMakeActionOnNonNullValue() { + //given + val id = "item_id" + val itemService = ItemService() + + //when + val result = itemService.findItemNameForId(id) + + //then + assertNotNull(result?.let { it -> it.id }) + assertNotNull(result!!.id) + } +} \ No newline at end of file