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

Commit 2332a7d

Browse files
committed
BoundKMapperでのコンバーター利用テストを追加
1 parent 6cbcfca commit 2332a7d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/test/kotlin/com/mapk/kmapper/ConverterKMapperTest.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class CompanionConverter private constructor(val arg: String) {
2525

2626
private data class StaticMethodConverterDst(val argument: StaticMethodConverter)
2727

28+
private data class BoundConstructorConverterSrc(val argument: Int)
29+
private data class BoundCompanionConverterSrc(val argument: String)
30+
private data class BoundStaticMethodConverterSrc(val argument: String)
31+
2832
@DisplayName("コンバータ有りでのマッピングテスト")
2933
class ConverterKMapperTest {
3034
@Nested
@@ -57,4 +61,35 @@ class ConverterKMapperTest {
5761
assertTrue(intArrayOf(1, 2, 3) contentEquals result.argument.arg)
5862
}
5963
}
64+
65+
@Nested
66+
@DisplayName("BoundKMapper")
67+
inner class BoundKMapperTest {
68+
@Test
69+
@DisplayName("コンストラクターでのコンバートテスト")
70+
fun constructorConverterTest() {
71+
val mapper = BoundKMapper(::ConstructorConverterDst, BoundConstructorConverterSrc::class)
72+
val result = mapper.map(BoundConstructorConverterSrc(1))
73+
74+
assertEquals(ConstructorConverter(1), result.argument)
75+
}
76+
77+
@Test
78+
@DisplayName("コンパニオンオブジェクトに定義したコンバータでのコンバートテスト")
79+
fun companionConverterTest() {
80+
val mapper = BoundKMapper(::CompanionConverterDst, BoundCompanionConverterSrc::class)
81+
val result = mapper.map(BoundCompanionConverterSrc("arg"))
82+
83+
assertEquals("arg", result.argument.arg)
84+
}
85+
86+
@Test
87+
@DisplayName("スタティックメソッドに定義したコンバータでのコンバートテスト")
88+
fun staticMethodConverterTest() {
89+
val mapper = BoundKMapper(::StaticMethodConverterDst, BoundStaticMethodConverterSrc::class)
90+
val result = mapper.map(BoundStaticMethodConverterSrc("1,2,3"))
91+
92+
assertTrue(intArrayOf(1, 2, 3) contentEquals result.argument.arg)
93+
}
94+
}
6095
}

0 commit comments

Comments
 (0)