Kotlin, MyBatis, Dagger Integration Test


#1

Hi everyone, i 'm having trouble to instantiate interfaces like i do in java spring mybatis, with this kotlin, dagger, mybatis stack.
This is what my code looks like:

Interface to myBatis Mapper:

@Component
interface ClientMapper {
    fun retrieveById(@Param("id") idClient : Int) : Optional<EClient>
    fun retrieveList() : List<EClient>
    fun create(@Param("client")eclient : EClient) : Int
    fun update(@Param("client")eclient: EClient) : Int
}

Integration test

class ClientMapperIntegrationTest{

lateinit var mapper: ClientMapper

@Test
fun retrieveById(){
    val idClient = 1
    
    val client = mapper.retrieveById(idClient)

    assertEntity(client)

}

private fun assertEntity(client: Optional<EClient>) {
    Assert.assertTrue(client.isPresent )
    Assert.assertEquals(client.get().nom , "jean")
}

}

(i won’t post here my mapper query neither resultMap cause its not the problem)

Dagger can’t construct interfaces with annotation @Inject. mybatis have its own way to deal with my interface and i dont have to implement my interface because it will be used by XML mapper query.

I have an error when running test telling me that interface have to be initialized:
kotlin.UninitializedPropertyAccessException: lateinit property mapper has not been initialized

I do understand why but i dont know how to do this in kotlin and dagger