Created
November 10, 2018 10:52
-
-
Save satoshun/93a575390a130e54fcf8649ef129a89f 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
@UseExperimental(ExperimentalContracts::class) | |
fun <T : Activity> ActivityScenario<T>.onActivity2(block: (T) -> Unit) { | |
contract { | |
callsInPlace(block, InvocationKind.EXACTLY_ONCE) | |
} | |
onActivity { | |
block(it) | |
} | |
} |
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
import kotlin.contracts.ExperimentalContracts | |
import kotlin.contracts.InvocationKind | |
import kotlin.contracts.contract | |
@RunWith(AndroidJUnit4::class) | |
internal class OnActivityContractTest { | |
@Test | |
fun onActivityContract() { | |
val scenario = ActivityScenario.launch(Activity::class.java) | |
val activity: Activity | |
scenario.onActivity2 { | |
activity = it | |
} | |
println(activity) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment