Invoke onTick immediately in onResume.

This commit is contained in:
Alex Hart
2021-06-21 14:33:23 -03:00
committed by Cody Henthorne
parent b3041ab6e0
commit b93568d9c6
2 changed files with 11 additions and 11 deletions

View File

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

View File

@@ -30,27 +30,27 @@ class ConversationUpdateTickTest {
} }
@Test @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 // GIVEN
ShadowLooper.pauseMainLooper() ShadowLooper.pauseMainLooper()
testSubject.onResume(lifecycleOwner) testSubject.onResume(lifecycleOwner)
// THEN // THEN
verify(listener, never()).onTick() verify(listener, times(1)).onTick()
} }
@Test @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 // GIVEN
testSubject.onResume(lifecycleOwner) testSubject.onResume(lifecycleOwner)
ShadowLooper.idleMainLooper(timeoutMillis / 2, TimeUnit.MILLISECONDS) ShadowLooper.idleMainLooper(timeoutMillis / 2, TimeUnit.MILLISECONDS)
// THEN // THEN
verify(listener, never()).onTick() verify(listener, times(1)).onTick()
} }
@Test @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 // GIVEN
testSubject.onResume(lifecycleOwner) testSubject.onResume(lifecycleOwner)
@@ -58,11 +58,11 @@ class ConversationUpdateTickTest {
ShadowLooper.idleMainLooper(timeoutMillis, TimeUnit.MILLISECONDS) ShadowLooper.idleMainLooper(timeoutMillis, TimeUnit.MILLISECONDS)
// THEN // THEN
verify(listener, times(1)).onTick() verify(listener, times(2)).onTick()
} }
@Test @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 // GIVEN
testSubject.onResume(lifecycleOwner) testSubject.onResume(lifecycleOwner)
@@ -70,11 +70,11 @@ class ConversationUpdateTickTest {
ShadowLooper.idleMainLooper(timeoutMillis * 5, TimeUnit.MILLISECONDS) ShadowLooper.idleMainLooper(timeoutMillis * 5, TimeUnit.MILLISECONDS)
// THEN // THEN
verify(listener, times(5)).onTick() verify(listener, times(6)).onTick()
} }
@Test @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 // GIVEN
testSubject.onResume(lifecycleOwner) testSubject.onResume(lifecycleOwner)
testSubject.onPause(lifecycleOwner) testSubject.onPause(lifecycleOwner)
@@ -83,6 +83,6 @@ class ConversationUpdateTickTest {
ShadowLooper.idleMainLooper(timeoutMillis, TimeUnit.MILLISECONDS) ShadowLooper.idleMainLooper(timeoutMillis, TimeUnit.MILLISECONDS)
// THEN // THEN
verify(listener, never()).onTick() verify(listener, times(1)).onTick()
} }
} }