BAEL-382 null-safety example
This commit is contained in:
parent
3351d96147
commit
4d415f7f74
|
@ -14,6 +14,18 @@
|
|||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</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>
|
||||
|
||||
<build>
|
||||
|
@ -24,7 +36,6 @@
|
|||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>1.0.4</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package com.baeldung
|
||||
|
||||
|
||||
data class Item(val id: String, val name: String)
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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…
Reference in New Issue