use of org.robolectric.annotation.Config 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);
}
use of org.robolectric.annotation.Config 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);
}
use of org.robolectric.annotation.Config 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);
}
use of org.robolectric.annotation.Config in project FirebaseUI-Android by firebase.
the class AuthMethodPickerActivityTest method testTwitterLoginFlowStarts.
@Test
@Config(shadows = { ActivityHelperShadow.class })
public void testTwitterLoginFlowStarts() {
List<String> providers = Arrays.asList(AuthUI.TWITTER_PROVIDER);
AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(TwitterAuthProvider.PROVIDER_ID));
when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
Button twitterButton = (Button) authMethodPickerActivity.findViewById(R.id.twitter_button);
assertNotNull(twitterButton);
twitterButton.performClick();
ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
assertTrue(nextIntent.intent.getComponent().getClassName().contains("com.twitter.sdk"));
}
use of org.robolectric.annotation.Config in project robolectric by robolectric.
the class RobolectricTestRunner method getChildren.
@Override
protected List<FrameworkMethod> getChildren() {
List<FrameworkMethod> children = new ArrayList<>();
for (FrameworkMethod frameworkMethod : super.getChildren()) {
try {
Config config = getConfig(frameworkMethod.getMethod());
AndroidManifest appManifest = getAppManifest(config);
List<SdkConfig> sdksToRun = sdkPicker.selectSdks(config, appManifest);
RobolectricFrameworkMethod last = null;
for (SdkConfig sdkConfig : sdksToRun) {
last = new RobolectricFrameworkMethod(frameworkMethod.getMethod(), appManifest, sdkConfig, config);
children.add(last);
}
if (last != null) {
last.dontIncludeApiLevelInName();
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("failed to configure " + getTestClass().getName() + "." + frameworkMethod.getMethod().getName() + ": " + e.getMessage(), e);
}
}
return children;
}
Aggregations