Search in sources :

Example 1 with BaseHelperShadow

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

the class RegisterEmailActivityTest method testSignUpButton_successfulRegistrationShouldContinueToSaveCredentials.

@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testSignUpButton_successfulRegistrationShouldContinueToSaveCredentials() {
    // init mocks
    new BaseHelperShadow();
    reset(BaseHelperShadow.sSaveSmartLock);
    TestHelper.initializeApp(RuntimeEnvironment.application);
    RegisterEmailActivity registerEmailActivity = createActivity();
    // Trigger new user UI (bypassing check email)
    registerEmailActivity.onNewUser(new User.Builder(TestConstants.EMAIL).setName(TestConstants.NAME).setPhotoUri(TestConstants.PHOTO_URI).build());
    EditText name = (EditText) registerEmailActivity.findViewById(R.id.name);
    EditText password = (EditText) registerEmailActivity.findViewById(R.id.password);
    name.setText(TestConstants.NAME);
    password.setText(TestConstants.PASSWORD);
    FirebaseUser mockFirebaseUser = Mockito.mock(FirebaseUser.class);
    when(mockFirebaseUser.getEmail()).thenReturn(TestConstants.EMAIL);
    when(mockFirebaseUser.getDisplayName()).thenReturn(TestConstants.NAME);
    when(mockFirebaseUser.getPhotoUrl()).thenReturn(TestConstants.PHOTO_URI);
    when(mockFirebaseUser.updateProfile((UserProfileChangeRequest) Mockito.any())).thenReturn(new AutoCompleteTask<Void>(null, true, null));
    when(BaseHelperShadow.sFirebaseAuth.createUserWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button button = (Button) registerEmailActivity.findViewById(R.id.button_create);
    button.performClick();
    TestHelper.verifySmartLockSave(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL, TestConstants.PASSWORD);
}
Also used : EditText(android.widget.EditText) Button(android.widget.Button) BaseHelperShadow(com.firebase.ui.auth.testhelpers.BaseHelperShadow) 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)

Aggregations

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