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()
}
}
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.