Skip to content

Commit 3a67102

Browse files
committed
Tests for name conflicts and Kotlin lambda
1 parent 3e0e4b7 commit 3a67102

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

src/test/kotlin/examples/kotlin/mybatis3/joins/JoinMapper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import org.apache.ibatis.annotations.ResultMap
1919
import org.apache.ibatis.annotations.SelectProvider
2020
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider
2121
import org.mybatis.dynamic.sql.util.SqlProviderAdapter
22+
import org.mybatis.dynamic.sql.util.mybatis3.GeneralMapper
2223

23-
interface JoinMapper {
24+
interface JoinMapper : GeneralMapper {
2425
@SelectProvider(type = SqlProviderAdapter::class, method = "select")
2526
@ResultMap("SimpleJoinResult")
2627
fun selectMany(selectStatement: SelectStatementProvider): List<OrderMaster>

src/test/kotlin/examples/kotlin/mybatis3/joins/JoinMapperTest.kt

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import org.assertj.core.api.Assertions.entry
3131
import org.junit.jupiter.api.Test
3232
import org.mybatis.dynamic.sql.SqlBuilder.*
3333
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.from
34-
import org.mybatis.dynamic.sql.util.mybatis3.GeneralMapper
3534
import java.io.InputStreamReader
3635
import java.sql.DriverManager
3736

@@ -51,7 +50,6 @@ class JoinMapperTest {
5150
val environment = Environment("test", JdbcTransactionFactory(), ds)
5251
val config = Configuration(environment)
5352
config.addMapper(JoinMapper::class.java)
54-
config.addMapper(GeneralMapper::class.java)
5553
return SqlSessionFactoryBuilder().build(config).openSession()
5654
}
5755

@@ -161,7 +159,7 @@ class JoinMapperTest {
161159
@Test
162160
fun testFullJoinWithAliases() {
163161
newSession().use { session ->
164-
val mapper = session.getMapper(GeneralMapper::class.java)
162+
val mapper = session.getMapper(JoinMapper::class.java)
165163

166164
val selectStatement = select(OrderLine.orderId, OrderLine.quantity, ItemMaster.itemId,
167165
ItemMaster.description).from(OrderMaster, "om") {
@@ -181,33 +179,46 @@ class JoinMapperTest {
181179

182180
assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement)
183181

184-
val rows = mapper.selectManyMappedRows(selectStatement)
182+
data class OrderDetail (val itemId: Int?, val orderId: Int?, val quantity: Int?, val description: String?)
183+
184+
val rows = mapper.selectMany(selectStatement) {
185+
OrderDetail(
186+
it["ITEM_ID"] as Int?,
187+
it["ORDER_ID"] as Int?,
188+
it["QUANTITY"] as Int?,
189+
it["DESCRIPTION"] as String?
190+
)
191+
}
185192

186193
assertThat(rows).hasSize(6)
187194

188-
assertThat(rows[0]).containsExactly(
189-
entry("DESCRIPTION", "Catcher Glove"),
190-
entry("ITEM_ID", 55)
191-
)
195+
with(rows[0]) {
196+
assertThat(itemId).isEqualTo(55)
197+
assertThat(orderId).isNull()
198+
assertThat(quantity).isNull()
199+
assertThat(description).isEqualTo("Catcher Glove")
200+
}
192201

193-
assertThat(rows[3]).containsExactly(
194-
entry("ORDER_ID", 2),
195-
entry("QUANTITY", 6)
196-
)
202+
with(rows[3]) {
203+
assertThat(itemId).isNull()
204+
assertThat(orderId).isEqualTo(2)
205+
assertThat(quantity).isEqualTo(6)
206+
assertThat(description).isNull()
207+
}
197208

198-
assertThat(rows[5]).containsExactly(
199-
entry("ORDER_ID", 2),
200-
entry("QUANTITY", 1),
201-
entry("DESCRIPTION", "Outfield Glove"),
202-
entry("ITEM_ID", 44)
203-
)
209+
with(rows[5]) {
210+
assertThat(itemId).isEqualTo(44)
211+
assertThat(orderId).isEqualTo(2)
212+
assertThat(quantity).isEqualTo(1)
213+
assertThat(description).isEqualTo("Outfield Glove")
214+
}
204215
}
205216
}
206217

207218
@Test
208219
fun testFullJoinWithoutAliases() {
209220
newSession().use { session ->
210-
val mapper = session.getMapper(GeneralMapper::class.java)
221+
val mapper = session.getMapper(JoinMapper::class.java)
211222

212223
val selectStatement = select(OrderLine.orderId, OrderLine.quantity, ItemMaster.itemId,
213224
ItemMaster.description).from(OrderMaster, "om") {
@@ -253,7 +264,7 @@ class JoinMapperTest {
253264
@Test
254265
fun testLeftJoinWithAliases() {
255266
newSession().use { session ->
256-
val mapper = session.getMapper(GeneralMapper::class.java)
267+
val mapper = session.getMapper(JoinMapper::class.java)
257268

258269
val selectStatement = select(OrderLine.orderId, OrderLine.quantity, ItemMaster.itemId,
259270
ItemMaster.description).from(OrderMaster, "om") {
@@ -294,7 +305,7 @@ class JoinMapperTest {
294305
@Test
295306
fun testLeftJoinWithoutAliases() {
296307
newSession().use { session ->
297-
val mapper = session.getMapper(GeneralMapper::class.java)
308+
val mapper = session.getMapper(JoinMapper::class.java)
298309

299310
val selectStatement = select(OrderLine.orderId, OrderLine.quantity, ItemMaster.itemId,
300311
ItemMaster.description).from(OrderMaster, "om") {
@@ -335,7 +346,7 @@ class JoinMapperTest {
335346
@Test
336347
fun testRightJoinWithAliases() {
337348
newSession().use { session ->
338-
val mapper = session.getMapper(GeneralMapper::class.java)
349+
val mapper = session.getMapper(JoinMapper::class.java)
339350

340351
val selectStatement = select(OrderLine.orderId, OrderLine.quantity, ItemMaster.itemId,
341352
ItemMaster.description).from(OrderMaster, "om") {
@@ -376,7 +387,7 @@ class JoinMapperTest {
376387
@Test
377388
fun testRightJoinWithoutAliases() {
378389
newSession().use { session ->
379-
val mapper = session.getMapper(GeneralMapper::class.java)
390+
val mapper = session.getMapper(JoinMapper::class.java)
380391

381392
val selectStatement = select(OrderLine.orderId, OrderLine.quantity, ItemMaster.itemId,
382393
ItemMaster.description).from(OrderMaster, "om") {

0 commit comments

Comments
 (0)