Created
February 20, 2019 14:00
-
-
Save yshrsmz/04ec225f682041d9cd4041546bd8a3e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codingfeline.sample | |
import android.os.Build | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
import org.kodein.di.Kodein | |
import org.kodein.di.KodeinAware | |
import org.kodein.di.erased.bind | |
import org.kodein.di.erased.instance | |
import org.kodein.di.erased.provider | |
import org.kodein.di.erased.singleton | |
import org.robolectric.RobolectricTestRunner | |
import org.robolectric.annotation.Config | |
import kotlin.test.assertSame | |
@Config( | |
sdk = [Build.VERSION_CODES.P], | |
manifest = Config.NONE | |
) | |
@RunWith(RobolectricTestRunner::class) | |
class KodeinTest : KodeinAware { | |
override val kodein = Kodein { | |
bind<AndroidLog>(tag = "android") with singleton { AndroidLog() } | |
bind<CommonLog>(tag = "common") with provider { instance<AndroidLog>(tag = "android") } | |
} | |
val logger: CommonLog by instance(tag = "common") | |
val aLogger: AndroidLog by instance(tag = "android") | |
@Test | |
fun test() { | |
logger.log("test") | |
assertSame(logger, aLogger) | |
} | |
interface CommonLog { | |
fun log(msg: String) | |
} | |
class AndroidLog : CommonLog { | |
override fun log(msg: String) { | |
println(msg) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment