I use AnkoLogger, but it blocks my unit tests. I ...
# anko
j
I use AnkoLogger, but it blocks my unit tests. I had already created a wrapper around it so that I could log to Crashlytics at the same time. I have a thought now that I can maybe create an anonymous object that implements AnkoLogger and has methods that have the same signature as the extension methods, but are empty. I thought if an instance method and an extension method have the same name, the instance method would win (per this article: https://android.jlelse.eu/the-ugly-truth-about-extension-functions-in-kotlin-486ec49824f4) but it isn’t working. Is this crazy? Am I never going to get this to work?
Copy code
fun Logger(): Logger = object : Logger {}

var ankoLoggerInstance: (loggerTag: String) -> AnkoLogger = { loggerTag -> AnkoLogger(loggerTag) }

fun Logger.verbose(message: Any?) {
    ankoLoggerInstance(loggerTag).verbose(message)
}
Copy code
class TestKodein {

    companion object {
        @BeforeClass
        @JvmStatic
        fun setup() {
            crashlyticsInstance = { DummyCrashlyticsCoreProxy() }
            ankoLoggerInstance = {
                object : AnkoLogger {
                    fun verbose(message: Any?, thr: Throwable? = null) {}
                    fun debug(message: Any?, thr: Throwable? = null) {}
                    fun info(message: Any?, thr: Throwable? = null) {}
                    fun error(message: Any?, thr: Throwable? = null) {}
                    fun warning(message: Any?, thr: Throwable? = null) {}
                    fun wtf(message: Any?, thr: Throwable? = null) {}
                }
            }
        }
    }

...