Source:
public void testSignInFailed_withPasswordAccountAlreadyLinked() { Activity mockActivty = mock(Activity.class); ActivityHelper mockActivityHelper = mock(ActivityHelper.class); FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class); IDPResponse mockIdpResponse = mock(IDPResponse.class); when(mockIdpResponse.getEmail()).thenReturn(TestConstants.EMAIL); 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(EmailAuthProvider.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( WelcomeBackPasswordPrompt.class.getName(), capturedIntent.getComponent().getClassName()); assertEquals( TestConstants.EMAIL, ((IDPResponse) capturedIntent.getExtras().getParcelable(ExtraConstants .EXTRA_IDP_RESPONSE)).getEmail()); }

Target:
public void testSignInFailed_withPasswordAccountAlreadyLinked() { 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); Task mockTask = mock(Task.class); FlowParameters mockFlowParams = mock(FlowParameters.class); when(mockTask.getException()).thenReturn( new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION)); 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(EmailAuthProvider.PROVIDER_ID)), true, null)); credentialSignInHandler.onComplete(mockTask); 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( WelcomeBackPasswordPrompt.class.getName(), capturedIntent.getComponent().getClassName()); assertEquals( TestConstants.EMAIL, ((IDPResponse) capturedIntent.getExtras().getParcelable(ExtraConstants .EXTRA_IDP_RESPONSE)).getEmail()); }