File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414 <artifactId >kotlin-stdlib</artifactId >
1515 <version >1.0.4</version >
1616 </dependency >
17+ <dependency >
18+ <groupId >org.jetbrains.kotlin</groupId >
19+ <artifactId >kotlin-test-junit</artifactId >
20+ <version >1.0.4</version >
21+ <scope >test</scope >
22+ </dependency >
23+ <dependency >
24+ <groupId >junit</groupId >
25+ <artifactId >junit</artifactId >
26+ <version >4.12</version >
27+ <scope >test</scope >
28+ </dependency >
1729 </dependencies >
1830
1931 <build >
2436 <artifactId >kotlin-maven-plugin</artifactId >
2537 <groupId >org.jetbrains.kotlin</groupId >
2638 <version >1.0.4</version >
27-
2839 <executions >
2940 <execution >
3041 <id >compile</id >
Original file line number Diff line number Diff line change 1+ package com.baeldung
2+
3+
4+ data class Item (val id : String , val name : String )
Original file line number Diff line number Diff line change 1+ package com.baeldung
2+
3+ import java.util.*
4+
5+ class ItemService {
6+ fun findItemNameForId (id : String ): Item ? {
7+ val itemId = UUID .randomUUID().toString()
8+ return Item (itemId, " name-$itemId " );
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung
2+
3+ import org.junit.Test
4+ import kotlin.test.assertNotNull
5+
6+ class ItemServiceTest {
7+ @Test
8+ fun givenItemId_whenGetForOptionalName_shouldMakeActionOnNonNullValue () {
9+ // given
10+ val id = " item_id"
11+ val itemService = ItemService ()
12+
13+ // when
14+ val result = itemService.findItemNameForId(id)
15+
16+ // then
17+ assertNotNull(result?.let { it -> it.id })
18+ assertNotNull(result!! .id)
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments