jeudi 11 avril 2019

Test logger call in Kotlin

I have a Kotlin class like this one

import org.slf4j.LoggerFactory.getLogger
object Doer {
    val logger = LoggerFactory.getLogger(Doer::class.java)

    override fun doSomething() {
        logger.warn("Doing.")
        return 123
    }
}

I would like to have a unit test that verifies logger.warn call was made with relevant message. How do I do this in Kotlin? One of my ideas was to use a getter for logger and stub that with Mockito, but do I need to declare such method explicitly given that Kotlin generates getters automatically? Are there better options?

Aucun commentaire:

Enregistrer un commentaire