11package com.mapk.krowmapper
22
33import com.google.common.base.CaseFormat
4+ import javax.sql.DataSource
45import org.h2.jdbcx.JdbcDataSource
6+ import org.junit.jupiter.api.Assertions.assertEquals
57import org.junit.jupiter.api.BeforeAll
68import org.junit.jupiter.api.Test
79import org.junit.jupiter.api.TestInstance
810import org.springframework.jdbc.core.JdbcTemplate
911import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource
1012import org.springframework.jdbc.core.simple.SimpleJdbcInsert
11- import javax.sql.DataSource
1213
1314@TestInstance(TestInstance .Lifecycle .PER_CLASS )
1415class UseDBMappingTest {
@@ -22,7 +23,19 @@ class UseDBMappingTest {
2223 val fooStatus : FooStatus ,
2324 val isBar : Boolean ,
2425 val description : String?
25- )
26+ ) {
27+ companion object {
28+ fun fooFactory (
29+ fooId : Int ,
30+ fooName : String ,
31+ fooStatus : FooStatus ,
32+ isBar : String ,
33+ description : String?
34+ ) = Foo (
35+ fooId, fooName, fooStatus, isBar.toBoolean(), description
36+ )
37+ }
38+ }
2639
2740 data class FooInsert (
2841 val fooId : Int ,
@@ -63,9 +76,13 @@ class UseDBMappingTest {
6376
6477 @Test
6578 fun test () {
66- val result = jdbcTemplate.query(" SELECT * FROM foo_table" , KRowMapper (:: Foo ) {
79+ val result = jdbcTemplate.query(" SELECT * FROM foo_table" , KRowMapper (( Foo )::fooFactory ) {
6780 CaseFormat .LOWER_CAMEL .to(CaseFormat .LOWER_UNDERSCORE , it)
68- })
69- println (result)
81+ }).single()
82+
83+ assertEquals(
84+ Foo (10 , " Foo" , FooStatus .archive, false , null ),
85+ result
86+ )
7087 }
7188}
0 commit comments