Skip to content

Fix test error #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

testOptions {
unitTests.all {
testLogging {
exceptionFormat = 'full'
}
}
}
}


dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
Expand Down
6 changes: 6 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.annotation.VisibleForTesting;

import com.facebook.FacebookSdk;
import com.facebook.login.LoginManager;
Expand Down Expand Up @@ -416,6 +417,11 @@ public SignInIntentBuilder setIsSmartLockEnabled(boolean enabled) {

public Intent build() {
Context context = mApp.getApplicationContext();
return build(context);
}

@VisibleForTesting
public Intent build(Context context) {
List<IDPProviderParcel> providerInfo =
ProviderHelper.getProviderParcels(context, mProviders);
return ChooseAccountActivity.createIntent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.firebase.ui.auth.test_helpers.TestHelper;
import com.firebase.ui.auth.ui.idp.IDPSignInContainerActivity;
import com.firebase.ui.auth.util.CredentialsAPI;
import com.firebase.ui.auth.util.PlayServicesHelper;
import com.google.android.gms.auth.api.credentials.IdentityProviders;
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.AuthResult;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class ChooseAccountActivityTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mFirebaseApp = TestHelper.initializeApp(RuntimeEnvironment.application);
PlayServicesHelper.sApiAvailability = TestHelper.makeMockGoogleApiAvailability();

when(mCredentialsAPI.isPlayServicesAvailable()).thenReturn(true);
when(mCredentialsAPI.isCredentialsAvailable()).thenReturn(true);
when(mCredentialsAPI.isAutoSignInAvailable()).thenReturn(true);
Expand All @@ -73,15 +76,17 @@ private Intent createStartIntent() {
.createSignInIntentBuilder()
.setProviders(AuthUI.EMAIL_PROVIDER, AuthUI.GOOGLE_PROVIDER)
.setIsSmartLockEnabled(true)
.build();
.build(RuntimeEnvironment.application);
}

@Test
public void testAutoSignInWithSavedUsernameAndPassword_signsIn() {
Intent startIntent = createStartIntent();
ChooseAccountActivity chooseAccountActivity =
Robolectric.buildActivity(ChooseAccountActivity.class)
.withIntent(createStartIntent()).create().get();
.withIntent(startIntent)
.create()
.get();

when(mCredentialsAPI.getEmailFromCredential()).thenReturn(TestConstants.EMAIL);
when(mCredentialsAPI.getPasswordFromCredential()).thenReturn(TestConstants.PASSWORD);
Expand Down Expand Up @@ -113,7 +118,10 @@ public void testAutoSignInWithSavedIdp_redirectsToIdpSignIn() {
Intent startIntent = createStartIntent();
ChooseAccountActivity chooseAccountActivity =
Robolectric.buildActivity(ChooseAccountActivity.class)
.withIntent(startIntent).create().get();
.withIntent(startIntent)
.create()
.get();

when(mCredentialsAPI.getEmailFromCredential()).thenReturn(TestConstants.EMAIL);
when(mCredentialsAPI.getPasswordFromCredential()).thenReturn(null);
when(mCredentialsAPI.getAccountTypeFromCredential()).thenReturn(
Expand Down