BAEL-382 null-safety example
This commit is contained in:
parent
3351d96147
commit
4d415f7f74
@ -14,6 +14,18 @@
|
|||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib</artifactId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-test-junit</artifactId>
|
||||||
|
<version>1.0.4</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -24,7 +36,6 @@
|
|||||||
<artifactId>kotlin-maven-plugin</artifactId>
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.4</version>
|
||||||
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>compile</id>
|
<id>compile</id>
|
||||||
|
4
kotlin/src/main/kotlin/com/baeldung/Item.kt
Normal file
4
kotlin/src/main/kotlin/com/baeldung/Item.kt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package com.baeldung
|
||||||
|
|
||||||
|
|
||||||
|
data class Item(val id: String, val name: String)
|
10
kotlin/src/main/kotlin/com/baeldung/ItemService.kt
Normal file
10
kotlin/src/main/kotlin/com/baeldung/ItemService.kt
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
20
kotlin/src/test/kotlin/com/baeldung/ItemServiceTest.kt
Normal file
20
kotlin/src/test/kotlin/com/baeldung/ItemServiceTest.kt
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user