Skip to content

Commit b17ea3b

Browse files
authored
Fix test error (#261)
* Fix broken tests Change-Id: Icfc4e7adf5d08904ea707a98afb97108a2dcd8b9 * Add context overload Change-Id: Ieb1c289837cedc63e0b8c79c8034ac88301df4b1 * Better test output Change-Id: I3225e08a37a6dfea0b2925f6b2d6c5fc421becc3 * Play Services helper Change-Id: I5674b71791cb47c79dfbb6d167eb67c0b95d9ee1
1 parent 710cdef commit b17ea3b

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

auth/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ android {
1717
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1818
}
1919
}
20+
21+
testOptions {
22+
unitTests.all {
23+
testLogging {
24+
exceptionFormat = 'full'
25+
}
26+
}
27+
}
2028
}
2129

30+
2231
dependencies {
2332
testCompile 'junit:junit:4.12'
2433
testCompile 'org.mockito:mockito-core:1.10.19'

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.support.annotation.NonNull;
2222
import android.support.annotation.Nullable;
2323
import android.support.annotation.StyleRes;
24+
import android.support.annotation.VisibleForTesting;
2425

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

417418
public Intent build() {
418419
Context context = mApp.getApplicationContext();
420+
return build(context);
421+
}
422+
423+
@VisibleForTesting
424+
public Intent build(Context context) {
419425
List<IDPProviderParcel> providerInfo =
420426
ProviderHelper.getProviderParcels(context, mProviders);
421427
return ChooseAccountActivity.createIntent(

auth/src/test/java/com/firebase/ui/auth/ui/ChooseAccountActivityTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.firebase.ui.auth.test_helpers.TestHelper;
2727
import com.firebase.ui.auth.ui.idp.IDPSignInContainerActivity;
2828
import com.firebase.ui.auth.util.CredentialsAPI;
29+
import com.firebase.ui.auth.util.PlayServicesHelper;
2930
import com.google.android.gms.auth.api.credentials.IdentityProviders;
3031
import com.google.firebase.FirebaseApp;
3132
import com.google.firebase.auth.AuthResult;
@@ -63,6 +64,8 @@ public class ChooseAccountActivityTest {
6364
public void setUp() {
6465
MockitoAnnotations.initMocks(this);
6566
mFirebaseApp = TestHelper.initializeApp(RuntimeEnvironment.application);
67+
PlayServicesHelper.sApiAvailability = TestHelper.makeMockGoogleApiAvailability();
68+
6669
when(mCredentialsAPI.isPlayServicesAvailable()).thenReturn(true);
6770
when(mCredentialsAPI.isCredentialsAvailable()).thenReturn(true);
6871
when(mCredentialsAPI.isAutoSignInAvailable()).thenReturn(true);
@@ -73,15 +76,17 @@ private Intent createStartIntent() {
7376
.createSignInIntentBuilder()
7477
.setProviders(AuthUI.EMAIL_PROVIDER, AuthUI.GOOGLE_PROVIDER)
7578
.setIsSmartLockEnabled(true)
76-
.build();
79+
.build(RuntimeEnvironment.application);
7780
}
7881

7982
@Test
8083
public void testAutoSignInWithSavedUsernameAndPassword_signsIn() {
8184
Intent startIntent = createStartIntent();
8285
ChooseAccountActivity chooseAccountActivity =
8386
Robolectric.buildActivity(ChooseAccountActivity.class)
84-
.withIntent(createStartIntent()).create().get();
87+
.withIntent(startIntent)
88+
.create()
89+
.get();
8590

8691
when(mCredentialsAPI.getEmailFromCredential()).thenReturn(TestConstants.EMAIL);
8792
when(mCredentialsAPI.getPasswordFromCredential()).thenReturn(TestConstants.PASSWORD);
@@ -113,7 +118,10 @@ public void testAutoSignInWithSavedIdp_redirectsToIdpSignIn() {
113118
Intent startIntent = createStartIntent();
114119
ChooseAccountActivity chooseAccountActivity =
115120
Robolectric.buildActivity(ChooseAccountActivity.class)
116-
.withIntent(startIntent).create().get();
121+
.withIntent(startIntent)
122+
.create()
123+
.get();
124+
117125
when(mCredentialsAPI.getEmailFromCredential()).thenReturn(TestConstants.EMAIL);
118126
when(mCredentialsAPI.getPasswordFromCredential()).thenReturn(null);
119127
when(mCredentialsAPI.getAccountTypeFromCredential()).thenReturn(

0 commit comments

Comments
 (0)