Kotlin单元测试增加默认方法查询.

This commit is contained in:
聂秋荣 2024-11-01 16:40:16 +08:00
parent 30342f3cfc
commit 549d4ea598
3 changed files with 31 additions and 3 deletions

View File

@ -1,7 +1,15 @@
apply plugin: 'kotlin'
compileKotlin{
kotlinOptions.jvmTarget = "1.8"
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjvm-default=all']
}
}
dependencies {

View File

@ -38,6 +38,15 @@ class ChainWrappersTest : BaseDbTest<UserMapper>() {
Assertions.assertEquals(4, Db.ktQuery(User::class.java).eq(User::id, 2).one().roleId)
}
@Test
fun testDefaultMethod() {
doTestAutoCommit(fun(m) {
Assertions.assertEquals("hello baomidou!", m.hello())
Assertions.assertNotNull(m.findById(1))
Assertions.assertNull(m.findById(-1))
})
}
@Test
fun testSetSql() {
Assertions.assertTrue(

View File

@ -1,5 +1,16 @@
package com.baomidou.mybatisplus.test.kotlin
import com.baomidou.mybatisplus.core.mapper.BaseMapper
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
interface UserMapper : BaseMapper<User>
interface UserMapper : BaseMapper<User> {
fun hello(): String {
return "hello baomidou!";
}
fun findById(id: Int): User? {
return selectOne(KtQueryWrapper(User::class.java).eq(User::id, id));
}
}