1
1
package com.mapk.krowmapper
2
2
3
3
import com.google.common.base.CaseFormat
4
+ import javax.sql.DataSource
4
5
import org.h2.jdbcx.JdbcDataSource
6
+ import org.junit.jupiter.api.Assertions.assertEquals
5
7
import org.junit.jupiter.api.BeforeAll
6
8
import org.junit.jupiter.api.Test
7
9
import org.junit.jupiter.api.TestInstance
8
10
import org.springframework.jdbc.core.JdbcTemplate
9
11
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource
10
12
import org.springframework.jdbc.core.simple.SimpleJdbcInsert
11
- import javax.sql.DataSource
12
13
13
14
@TestInstance(TestInstance .Lifecycle .PER_CLASS )
14
15
class UseDBMappingTest {
@@ -22,7 +23,19 @@ class UseDBMappingTest {
22
23
val fooStatus : FooStatus ,
23
24
val isBar : Boolean ,
24
25
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
+ }
26
39
27
40
data class FooInsert (
28
41
val fooId : Int ,
@@ -63,9 +76,13 @@ class UseDBMappingTest {
63
76
64
77
@Test
65
78
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 ) {
67
80
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
+ )
70
87
}
71
88
}
0 commit comments