Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This test verifies that the SplashScreenManager works as expected
class SplashScreenManagerTest {
@Test
fun when_user_is_not_logged_login_activity_should_be_invoked() {
Intents.init()
val activityScenario: ActivityScenario<TestActivity> =
ActivityScenario.launch(TestActivity::class.java)
activityScenario.onActivity {
val storage = PreferencesStorage(it)
val tokenManager = TokenManager(storage)
val intentFactory = SplashIntentFactory(it, tokenManager)
it.clearToken()
SplashTimingManager(it, intentFactory, 0)
}
activityScenario.moveToState(Lifecycle.State.STARTED)
intended(hasComponent(LoginActivity::class.java.name))
Intents.release()
activityScenario.close()
}
@Test
fun when_user_is_logged_home_activity_should_be_invoked() {
Intents.init()
val activityScenario: ActivityScenario<TestActivity> = ActivityScenario.launch(TestActivity::class.java)
activityScenario.onActivity {
val storage = PreferencesStorage(it)
val tokenManager = TokenManager(storage)
val intentFactory = SplashIntentFactory(it, tokenManager)
it returnToken "AnyToken123!"
SplashTimingManager(it, intentFactory, 0)
}
activityScenario.moveToState(Lifecycle.State.STARTED)
intended(hasComponent(HomeActivity::class.java.name))
Intents.release()
activityScenario.close()
}
@Test
fun when_user_exits_the_app_before_time_is_elapsed_no_intents_should_be_fired() {
Intents.init()
val activityScenario: ActivityScenario<TestActivity> = ActivityScenario.launch(TestActivity::class.java)
activityScenario.onActivity {
val storage = PreferencesStorage(it)
val tokenManager = TokenManager(storage)
val intentFactory = SplashIntentFactory(it, tokenManager)
it returnToken "AnyToken123!"
SplashTimingManager(it, intentFactory, 10000)
}
activityScenario.moveToState(Lifecycle.State.STARTED)
activityScenario.moveToState(Lifecycle.State.DESTROYED)
getIntents().map { it.component?.className }.forEach {
assertThat(it).doesNotContain("Login")
assertThat(it).doesNotContain("Home")
}
Intents.release()
activityScenario.close()
}
@After
fun tearDown() {
ApplicationProvider.getApplicationContext<Application>().clearToken()
}
}
@danilodequeiroz

This comment has been minimized.

Copy link

@danilodequeiroz danilodequeiroz commented Oct 4, 2019

Is there a way to get the called activity (activity B for example), using a scenario from the caller activity (activity A) using androidX apis?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.