Skip to content

Commit 43d43ca

Browse files
committed
Handling review comments
1 parent ebfed96 commit 43d43ca

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Intent
55
import android.net.Uri
66
import android.os.Bundle
77
import android.util.Log
8+
import androidx.annotation.VisibleForTesting
89
import androidx.lifecycle.DefaultLifecycleObserver
910
import androidx.lifecycle.LifecycleOwner
1011
import com.auth0.android.Auth0
@@ -231,10 +232,12 @@ public object WebAuthProvider {
231232
}
232233

233234
@JvmStatic
235+
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
234236
internal fun resetManagerInstance() {
235237
managerInstance = null
236238
}
237239

240+
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
238241
internal fun resetState() {
239242
managerInstance = null
240243
callbacks.clear()
@@ -678,6 +681,7 @@ public object WebAuthProvider {
678681
return this
679682
}
680683

684+
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
681685
internal fun withPKCE(pkce: PKCE): Builder {
682686
this.pkce = pkce
683687
return this

auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.kt

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)