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

Commit 2a41a6a

Browse files
committed
単純なマッピングのテストを実装
1 parent fa11a4a commit 2a41a6a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.mapk.krowmapper
2+
3+
import com.google.common.base.CaseFormat
4+
import com.mapk.core.KFunctionForCall
5+
import io.mockk.every
6+
import io.mockk.mockk
7+
import io.mockk.verify
8+
import java.sql.ResultSet
9+
import org.junit.jupiter.api.Assertions.assertEquals
10+
import org.junit.jupiter.api.DisplayName
11+
import org.junit.jupiter.api.Test
12+
13+
@DisplayName("単純なマッピングテスト")
14+
class SimpleMappingTest {
15+
data class Dst(val fooId: Int, val strValue: String)
16+
17+
private fun camelToSnake(camel: String): String = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, camel)
18+
19+
@Test
20+
@DisplayName("スネークケースsrc -> キャメルケースdst")
21+
fun test() {
22+
val resultSet = mockk<ResultSet>()
23+
every { resultSet.getObject("foo_id", any<Class<*>>()) } returns 1
24+
every { resultSet.getObject("str_value", any<Class<*>>()) } returns "str"
25+
26+
val result = KRowMapper(KFunctionForCall(::Dst), this::camelToSnake).mapRow(resultSet, 0)
27+
28+
assertEquals(1, result.fooId)
29+
assertEquals("str", result.strValue)
30+
31+
verify(exactly = 1) { resultSet.getObject("foo_id", Int::class.java) }
32+
verify(exactly = 1) { resultSet.getObject("str_value", String::class.java) }
33+
}
34+
}

0 commit comments

Comments
 (0)