Source:
public void testSignInFailed_withFacebookAlreadyLinked() { Activity mockActivty = mock(Activity.class); ActivityHelper mockActivityHelper = mock(ActivityHelper.class); FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class); IDPResponse mockIdpResponse = mock(IDPResponse.class); CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler( mockActivty, mockActivityHelper, RC_ACCOUNT_LINK, RC_SAVE_CREDENTIALS, mockIdpResponse); Context mockContext = mock(Context.class); Task mockTask = mock(Task.class); FlowParameters mockFlowParams = mock(FlowParameters.class); when(mockTask.getException()).thenReturn( new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION)); when(mockIdpResponse.getEmail()).thenReturn(TestConstants.EMAIL); when(mockActivityHelper.getFirebaseAuth()).thenReturn(mockFirebaseAuth); when(mockActivityHelper.getApplicationContext()).thenReturn(mockContext); when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams); when(mockFirebaseAuth.fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn( new AutoCompleteTask<ProviderQueryResult>( new FakeProviderQueryResult( Arrays.asList(FacebookAuthProvider.PROVIDER_ID)), true, null)); credentialSignInHandler.onComplete(mockTask); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class); verify(mockActivty).startActivityForResult(intentCaptor.capture(), intCaptor.capture()); Intent capturedIntent = intentCaptor.getValue(); assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue()); assertEquals( WelcomeBackIDPPrompt.class.getName(), capturedIntent.getComponent().getClassName()); assertEquals( TestConstants.EMAIL, capturedIntent.getExtras().getString(ExtraConstants.EXTRA_EMAIL)); assertEquals( FacebookAuthProvider.PROVIDER_ID, capturedIntent.getExtras().getString(ExtraConstants.EXTRA_PROVIDER)); }

Target:
public void testSignInFailed_withFacebookAlreadyLinked() { Activity mockActivity = mock(Activity.class); ActivityHelper mockActivityHelper = mock(ActivityHelper.class); FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class); IDPResponse idpResponse = new IDPResponse( GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL, new Bundle()); CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler( mockActivity, mockActivityHelper, RC_ACCOUNT_LINK, RC_SAVE_CREDENTIALS, idpResponse); Context mockContext = mock(Context.class); FlowParameters mockFlowParams = mock(FlowParameters.class); when(mockActivityHelper.getFirebaseAuth()).thenReturn(mockFirebaseAuth); when(mockActivityHelper.getApplicationContext()).thenReturn(mockContext); when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams); when(mockFirebaseAuth.fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn( new AutoCompleteTask<ProviderQueryResult>( new FakeProviderQueryResult( Arrays.asList(FacebookAuthProvider.PROVIDER_ID)), true, null)); Task exceptionTask = Tasks.forException( new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION)); credentialSignInHandler.onComplete(exceptionTask); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class); verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture()); Intent capturedIntent = intentCaptor.getValue(); assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue()); assertEquals( WelcomeBackIDPPrompt.class.getName(), capturedIntent.getComponent().getClassName()); assertEquals( TestConstants.EMAIL, capturedIntent.getExtras().getString(ExtraConstants.EXTRA_EMAIL)); assertEquals( FacebookAuthProvider.PROVIDER_ID, capturedIntent.getExtras().getString(ExtraConstants.EXTRA_PROVIDER)); }