Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 6442480

Browse files
committed
インスタンスからマップするテストを追加
1 parent 97d2da0 commit 6442480

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/test/kotlin/mapk/core/SimpleKMapperTest.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ data class Dst(
1919
}
2020
}
2121

22+
data class Src1(
23+
val arg2: String?
24+
) {
25+
val arg1: Int = arg2?.length ?: 0
26+
val arg3: Number
27+
get() = arg1.toByte()
28+
val arg4 = null
29+
}
30+
2231
@DisplayName("単純なマッピングのテスト")
2332
class SimpleKMapperTest {
2433
private fun instanceFunction(arg1: Int, arg2: String?, arg3: Number): Dst {
@@ -73,4 +82,40 @@ class SimpleKMapperTest {
7382
}
7483
}
7584
}
85+
86+
@Nested
87+
@DisplayName("インスタンスからマップ")
88+
inner class FromInstance {
89+
@Test
90+
@DisplayName("Nullを含まない場合")
91+
fun testWithoutNull() {
92+
val stringValue = "value"
93+
94+
val src = Src1(stringValue)
95+
96+
val dsts = mappers.map { it.map(src) }
97+
98+
assertEquals(dsts.distinct().size, 1)
99+
dsts.first().let {
100+
assertEquals(it.arg1, stringValue.length)
101+
assertEquals(it.arg2, stringValue)
102+
assertEquals(it.arg3, stringValue.length.toByte())
103+
}
104+
}
105+
106+
@Test
107+
@DisplayName("Nullを含む場合")
108+
fun testContainsNull() {
109+
val src = Src1(null)
110+
111+
val dsts = mappers.map { it.map(src) }
112+
113+
assertEquals(dsts.distinct().size, 1)
114+
dsts.first().let {
115+
assertEquals(it.arg1, 0)
116+
assertEquals(it.arg2, null)
117+
assertEquals(it.arg3, 0.toByte())
118+
}
119+
}
120+
}
76121
}

0 commit comments

Comments
 (0)