Test case for verifying intent

Viewed 42
override fun getLaunchIntent(context: Context, params: Map<String, String>): Intent {
    return when (params["Activity"]) {
        "OneActivity" -> Intent(context,OneActivity::class.java)
        "TwoActivity" -> Intent(context, TwoActivity::class.java)
        else -> Intent(context, ThirdActivity::class.java)
    }
}

When we pass OneActivity as param, we need to verify that Intent is getting called/created. Can you guide me on this.

1 Answers

Might I make a suggestion?

You don't really need to test that Intent creation works, that's not the logic under test here. It makes more sense to me to alter your function to the below which could then be tested with a simple Unit test.

fun getLaunchClass(params: Map<String, String>): Class<*> {
    return when (params["Activity"]) {
        "OneActivity" -> OneActivity::class.java
        "TwoActivity" -> TwoActivity::class.java
        else -> ThirdActivity::class.java
    }
}
Related