@@ -3289,49 +3289,34 @@ public class WebAuthProviderTest {
32893289 }
32903290
32913291 @Test
3292- public fun shouldDeliverPendingLoginResultOnResume () {
3293- // Simulate the real flow: LifecycleAwareCallback's onDetached caches result,
3294- // then registerCallbacks' onResume picks it up.
3295- val credentials = Mockito .mock(Credentials ::class .java)
3296-
3297- // Create a LifecycleAwareCallback that caches to pendingLoginResult via onDetached
3298- val startLifecycleOwner = Mockito .mock(LifecycleOwner ::class .java)
3299- val startLifecycle = Mockito .mock(Lifecycle ::class .java)
3300- Mockito .`when `(startLifecycleOwner.lifecycle).thenReturn(startLifecycle)
3301-
3302- val startObserverCaptor = argumentCaptor<DefaultLifecycleObserver >()
3303- login(account).start(activity, callback)
3304-
3305- // Simulate Activity destroy (rotation) — nulls delegateCallback
3306- // Then simulate the result arriving after destroy via onDetached
3307- // We do this by triggering the LifecycleAwareCallback flow indirectly:
3308- // Register callbacks on a new lifecycle owner (the recreated Activity)
3309- val newLifecycleOwner = Mockito .mock(LifecycleOwner ::class .java)
3310- val newLifecycle = Mockito .mock(Lifecycle ::class .java)
3311- Mockito .`when `(newLifecycleOwner.lifecycle).thenReturn(newLifecycle)
3292+ public fun shouldNotDeliverLoginResultOnResumeWhenNoPendingResult () {
3293+ val lifecycleOwner = Mockito .mock(LifecycleOwner ::class .java)
3294+ val lifecycle = Mockito .mock(Lifecycle ::class .java)
3295+ Mockito .`when `(lifecycleOwner.lifecycle).thenReturn(lifecycle)
33123296
3313- val newCallback = Mockito .mock(Callback ::class .java) as Callback <Credentials , AuthenticationException >
33143297 val observerCaptor = argumentCaptor<DefaultLifecycleObserver >()
3315- WebAuthProvider .registerCallbacks(newLifecycleOwner , loginCallback = newCallback , logoutCallback = voidCallback)
3316- verify(newLifecycle ).addObserver(observerCaptor.capture())
3298+ WebAuthProvider .registerCallbacks(lifecycleOwner , loginCallback = callback , logoutCallback = voidCallback)
3299+ verify(lifecycle ).addObserver(observerCaptor.capture())
33173300
3318- // Result not yet delivered
3319- verify(newCallback, Mockito .never()).onSuccess(any())
3301+ // Trigger onResume with no pending result — should not deliver anything
3302+ observerCaptor.firstValue.onResume(lifecycleOwner)
3303+ verify(callback, Mockito .never()).onSuccess(any())
3304+ verify(callback, Mockito .never()).onFailure(any())
33203305 }
33213306
33223307 @Test
3323- public fun shouldDeliverPendingLogoutResultOnResume () {
3324- val newLifecycleOwner = Mockito .mock(LifecycleOwner ::class .java)
3325- val newLifecycle = Mockito .mock(Lifecycle ::class .java)
3326- Mockito .`when `(newLifecycleOwner .lifecycle).thenReturn(newLifecycle )
3308+ public fun shouldNotDeliverLogoutResultOnResumeWhenNoPendingResult () {
3309+ val lifecycleOwner = Mockito .mock(LifecycleOwner ::class .java)
3310+ val lifecycle = Mockito .mock(Lifecycle ::class .java)
3311+ Mockito .`when `(lifecycleOwner .lifecycle).thenReturn(lifecycle )
33273312
33283313 val observerCaptor = argumentCaptor<DefaultLifecycleObserver >()
3329- WebAuthProvider .registerCallbacks(newLifecycleOwner , loginCallback = callback, logoutCallback = voidCallback)
3330- verify(newLifecycle ).addObserver(observerCaptor.capture())
3314+ WebAuthProvider .registerCallbacks(lifecycleOwner , loginCallback = callback, logoutCallback = voidCallback)
3315+ verify(lifecycle ).addObserver(observerCaptor.capture())
33313316
3332- // No pending result — onResume should not deliver anything
3333- observerCaptor.firstValue.onResume(newLifecycleOwner)
3317+ observerCaptor.firstValue.onResume(lifecycleOwner)
33343318 verify(voidCallback, Mockito .never()).onSuccess(any())
3319+ verify(voidCallback, Mockito .never()).onFailure(any())
33353320 }
33363321
33373322 @Test
0 commit comments