Search in sources :

Example 1 with ActivityHelperShadow

use of com.firebase.ui.auth.testhelpers.ActivityHelperShadow in project FirebaseUI-Android by firebase.

the class AuthMethodPickerActivityTest method testFacebookLoginFlow.

@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testFacebookLoginFlow() {
    // initialize mocks
    new ActivityHelperShadow();
    reset(ActivityHelperShadow.sSaveSmartLock);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(FacebookAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    List<String> providers = Arrays.asList(AuthUI.FACEBOOK_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FacebookSdk.sdkInitialize(authMethodPickerActivity);
    Button facebookButton = (Button) authMethodPickerActivity.findViewById(R.id.facebook_button);
    assertNotNull(facebookButton);
    facebookButton.performClick();
    verifySmartLockSave(AuthUI.FACEBOOK_PROVIDER, TestConstants.EMAIL, null);
}
Also used : ActivityHelperShadow(com.firebase.ui.auth.testhelpers.ActivityHelperShadow) Button(android.widget.Button) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Example 2 with ActivityHelperShadow

use of com.firebase.ui.auth.testhelpers.ActivityHelperShadow in project FirebaseUI-Android by firebase.

the class AuthMethodPickerActivityTest method testGoogleLoginFlow.

@Test
@Config(shadows = { GoogleProviderShadow.class, BaseHelperShadow.class, ActivityHelperShadow.class })
public void testGoogleLoginFlow() {
    // initialize mocks
    new ActivityHelperShadow();
    reset(ActivityHelperShadow.sSaveSmartLock);
    List<String> providers = Arrays.asList(AuthUI.GOOGLE_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(GoogleAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button googleButton = (Button) authMethodPickerActivity.findViewById(R.id.google_button);
    assertNotNull(googleButton);
    googleButton.performClick();
    verifySmartLockSave(AuthUI.GOOGLE_PROVIDER, TestConstants.EMAIL, null);
}
Also used : ActivityHelperShadow(com.firebase.ui.auth.testhelpers.ActivityHelperShadow) Button(android.widget.Button) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Example 3 with ActivityHelperShadow

use of com.firebase.ui.auth.testhelpers.ActivityHelperShadow in project FirebaseUI-Android by firebase.

the class WelcomeBackPasswordPromptTest method testSignInButton_signsInAndSavesCredentials.

@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testSignInButton_signsInAndSavesCredentials() {
    // initialize mocks
    new ActivityHelperShadow();
    reset(ActivityHelperShadow.sSaveSmartLock);
    WelcomeBackPasswordPrompt welcomeBackActivity = createActivity();
    EditText passwordField = (EditText) welcomeBackActivity.findViewById(R.id.password);
    passwordField.setText(TestConstants.PASSWORD);
    FirebaseUser mockFirebaseUser = mock(FirebaseUser.class);
    when(ActivityHelperShadow.sFirebaseAuth.signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    when(mockFirebaseUser.getDisplayName()).thenReturn(TestConstants.NAME);
    when(mockFirebaseUser.getEmail()).thenReturn(TestConstants.EMAIL);
    when(mockFirebaseUser.getPhotoUrl()).thenReturn(TestConstants.PHOTO_URI);
    Button signIn = (Button) welcomeBackActivity.findViewById(R.id.button_done);
    signIn.performClick();
    verify(ActivityHelperShadow.sFirebaseAuth).signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD);
    verifySmartLockSave(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL, TestConstants.PASSWORD);
}
Also used : ActivityHelperShadow(com.firebase.ui.auth.testhelpers.ActivityHelperShadow) EditText(android.widget.EditText) Button(android.widget.Button) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) WelcomeBackPasswordPrompt(com.firebase.ui.auth.ui.accountlink.WelcomeBackPasswordPrompt) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Aggregations

Button (android.widget.Button)3 BuildConfig (com.firebase.ui.auth.BuildConfig)3 ActivityHelperShadow (com.firebase.ui.auth.testhelpers.ActivityHelperShadow)3 FakeAuthResult (com.firebase.ui.auth.testhelpers.FakeAuthResult)3 AuthResult (com.google.firebase.auth.AuthResult)3 FirebaseUser (com.google.firebase.auth.FirebaseUser)3 Test (org.junit.Test)3 Config (org.robolectric.annotation.Config)3 EditText (android.widget.EditText)1 WelcomeBackPasswordPrompt (com.firebase.ui.auth.ui.accountlink.WelcomeBackPasswordPrompt)1