Invoke onTick immediately in onResume.

fork-5.53.8
Alex Hart 2021-06-21 14:33:23 -03:00 zatwierdzone przez Cody Henthorne
rodzic b3041ab6e0
commit b93568d9c6
2 zmienionych plików z 11 dodań i 11 usunięć

Wyświetl plik

@ -22,7 +22,7 @@ class ConversationUpdateTick(
isResumed = true
handler.removeCallbacksAndMessages(null)
handler.postDelayed(this::onTick, TIMEOUT)
onTick()
}
override fun onPause(owner: LifecycleOwner) {

Wyświetl plik

@ -30,27 +30,27 @@ class ConversationUpdateTickTest {
}
@Test
fun `Given no time has passed after onResume is invoked, then I expect zero invocations of onTick`() {
fun `Given no time has passed after onResume is invoked, then I expect one invocations of onTick`() {
// GIVEN
ShadowLooper.pauseMainLooper()
testSubject.onResume(lifecycleOwner)
// THEN
verify(listener, never()).onTick()
verify(listener, times(1)).onTick()
}
@Test
fun `Given onResume is invoked, when half timeout passes, then I expect zero invocations of onTick`() {
fun `Given onResume is invoked, when half timeout passes, then I expect one invocations of onTick`() {
// GIVEN
testSubject.onResume(lifecycleOwner)
ShadowLooper.idleMainLooper(timeoutMillis / 2, TimeUnit.MILLISECONDS)
// THEN
verify(listener, never()).onTick()
verify(listener, times(1)).onTick()
}
@Test
fun `Given onResume is invoked, when timeout passes, then I expect one invocation of onTick`() {
fun `Given onResume is invoked, when timeout passes, then I expect two invocations of onTick`() {
// GIVEN
testSubject.onResume(lifecycleOwner)
@ -58,11 +58,11 @@ class ConversationUpdateTickTest {
ShadowLooper.idleMainLooper(timeoutMillis, TimeUnit.MILLISECONDS)
// THEN
verify(listener, times(1)).onTick()
verify(listener, times(2)).onTick()
}
@Test
fun `Given onResume is invoked, when timeout passes five times, then I expect five invocations of onTick`() {
fun `Given onResume is invoked, when timeout passes five times, then I expect six invocations of onTick`() {
// GIVEN
testSubject.onResume(lifecycleOwner)
@ -70,11 +70,11 @@ class ConversationUpdateTickTest {
ShadowLooper.idleMainLooper(timeoutMillis * 5, TimeUnit.MILLISECONDS)
// THEN
verify(listener, times(5)).onTick()
verify(listener, times(6)).onTick()
}
@Test
fun `Given onResume then onPause is invoked, when timeout passes, then I expect no invocations of onTick`() {
fun `Given onResume then onPause is invoked, when timeout passes, then I expect one invocation of onTick`() {
// GIVEN
testSubject.onResume(lifecycleOwner)
testSubject.onPause(lifecycleOwner)
@ -83,6 +83,6 @@ class ConversationUpdateTickTest {
ShadowLooper.idleMainLooper(timeoutMillis, TimeUnit.MILLISECONDS)
// THEN
verify(listener, never()).onTick()
verify(listener, times(1)).onTick()
}
}