Skip to content

Commit

Permalink
fix tests by exposing a method to reset the manager-instance
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Jun 28, 2019
1 parent 1e77e1f commit 06b3b04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public LogoutBuilder withScheme(@NonNull String scheme) {
* @param callback to invoke when log out is successful
*/
public void start(Context context, VoidCallback callback) {

managerInstance = null;
resetManagerInstance();

if (!hasBrowserAppInstalled(context.getPackageManager())) {
Throwable cause = new ActivityNotFoundException("No Browser application installed.");
Expand Down Expand Up @@ -345,7 +344,7 @@ Builder withPKCE(PKCE pkce) {
*/
@Deprecated
public void start(@NonNull Activity activity, @NonNull AuthCallback callback, int requestCode) {
managerInstance = null;
resetManagerInstance();

if (useBrowser && !hasBrowserAppInstalled(activity.getPackageManager())) {
AuthenticationException ex = new AuthenticationException("a0.browser_not_available", "No Browser application installed to perform web authentication.");
Expand Down Expand Up @@ -447,7 +446,7 @@ public static boolean resume(int requestCode, int resultCode, @Nullable Intent i
final AuthorizeResult result = new AuthorizeResult(requestCode, resultCode, intent);
boolean success = managerInstance.resume(result);
if (success) {
managerInstance = null;
resetManagerInstance();
}
return success;
}
Expand All @@ -470,7 +469,7 @@ public static boolean resume(@Nullable Intent intent) {
final AuthorizeResult result = new AuthorizeResult(intent);
boolean success = managerInstance.resume(result);
if (success) {
managerInstance = null;
resetManagerInstance();
}
return success;

Expand All @@ -483,6 +482,11 @@ static ResumableManager getManagerInstance() {
return managerInstance;
}

@VisibleForTesting
static void resetManagerInstance() {
managerInstance = null;
}

@VisibleForTesting
static boolean hasBrowserAppInstalled(@NonNull PackageManager packageManager) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://auth0.com"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1660,13 +1660,17 @@ public void shouldFailToResumeLoginWithRequestCodeWithEmptyUriValues() throws Ex

@Test
public void shouldFailToResumeLoginWithIntentWithoutFirstInitProvider() throws Exception {
WebAuthProvider.resetManagerInstance();

Intent intent = createAuthIntent("");
assertFalse(WebAuthProvider.resume(intent));
}

@SuppressWarnings("deprecation")
@Test
public void shouldFailToResumeLoginWithRequestCodeWithoutFirstInitProvider() throws Exception {
WebAuthProvider.resetManagerInstance();

Intent intent = createAuthIntent("");
assertFalse(WebAuthProvider.resume(REQUEST_CODE, Activity.RESULT_OK, intent));
}
Expand Down

0 comments on commit 06b3b04

Please sign in to comment.