Skip to content

Commit d0d68a9

Browse files
author
Aaron Mandle
committed
Review feedback
1 parent 3eb46d9 commit d0d68a9

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

auth/src/main/java/com/firebase/ui/auth/ui/account_link/SaveCredentialsActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public void onConnected(@Nullable Bundle bundle) {
119119
builder.setProfilePictureUri(Uri.parse(mProfilePictureUri));
120120
}
121121
mActivityHelper.getCredentialsApi()
122-
.save(mCredentialsApiClient, builder.build()).setResultCallback(this);
122+
.save(mCredentialsApiClient, builder.build())
123+
.setResultCallback(this);
123124
}
124125

125126
@Override
@@ -186,7 +187,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
186187
if (resultCode == RESULT_OK) {
187188
Credential credential = new Credential.Builder(mEmail).setPassword(mPassword).build();
188189
mActivityHelper.getCredentialsApi()
189-
.save(mCredentialsApiClient, credential).setResultCallback(this);
190+
.save(mCredentialsApiClient, credential)
191+
.setResultCallback(this);
190192
} else {
191193
Log.e(TAG, "SAVE: Canceled by user");
192194
finish(RESULT_FIRST_USER, getIntent());

auth/src/test/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivityTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public void testAllProvidersArePopulated() {
7676
AuthUI.FACEBOOK_PROVIDER,
7777
AuthUI.GOOGLE_PROVIDER,
7878
AuthUI.EMAIL_PROVIDER);
79-
new GoogleProvider(null, null);
8079

8180
AuthMethodPickerActivity authMethodPickerActivity =
8281
createActivity(providers);

auth/src/test/java/com/firebase/ui/auth/ui/idp/CredentialSignInHandlerTest.java

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
115
package com.firebase.ui.auth.ui.idp;
216

317
import static junit.framework.Assert.assertEquals;
@@ -8,6 +22,7 @@
822
import android.app.Activity;
923
import android.content.Context;
1024
import android.content.Intent;
25+
import android.os.Bundle;
1126

1227
import com.firebase.ui.auth.BuildConfig;
1328
import com.firebase.ui.auth.provider.IDPResponse;
@@ -25,11 +40,13 @@
2540
import com.firebase.ui.auth.ui.account_link.WelcomeBackIDPPrompt;
2641
import com.firebase.ui.auth.ui.account_link.WelcomeBackPasswordPrompt;
2742
import com.google.android.gms.tasks.Task;
43+
import com.google.android.gms.tasks.Tasks;
2844
import com.google.firebase.auth.EmailAuthProvider;
2945
import com.google.firebase.auth.FacebookAuthProvider;
3046
import com.google.firebase.auth.FirebaseAuth;
3147
import com.google.firebase.auth.FirebaseAuthUserCollisionException;
3248
import com.google.firebase.auth.FirebaseUser;
49+
import com.google.firebase.auth.GoogleAuthProvider;
3350
import com.google.firebase.auth.ProviderQueryResult;
3451

3552
import org.junit.Test;
@@ -50,31 +67,29 @@ public class CredentialSignInHandlerTest {
5067

5168
@Test
5269
public void testSignInSucceeded() {
53-
Activity mockActivty = mock(Activity.class);
70+
Activity mockActivity = mock(Activity.class);
5471
ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
5572
FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
56-
IDPResponse mockIdpResponse = mock(IDPResponse.class);
57-
73+
IDPResponse idpResponse = new IDPResponse(
74+
GoogleAuthProvider.PROVIDER_ID,
75+
TestConstants.EMAIL,
76+
new Bundle());
5877
CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(
59-
mockActivty,
78+
mockActivity,
6079
mockActivityHelper,
6180
RC_ACCOUNT_LINK,
6281
RC_SAVE_CREDENTIALS,
63-
mockIdpResponse);
64-
82+
idpResponse);
6583
Context mockContext = mock(Context.class);
6684
FlowParameters mockFlowParams = mock(FlowParameters.class);
67-
Task mockTask = mock(Task.class);
68-
69-
when(mockTask.isSuccessful()).thenReturn(true);
70-
when(mockTask.getResult()).thenReturn(new FakeAuthResult(mockFirebaseUser));
85+
Task signInTask = Tasks.forResult(new FakeAuthResult(mockFirebaseUser));
7186
when(mockActivityHelper.getApplicationContext()).thenReturn(mockContext);
7287
when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams);
73-
credentialSignInHandler.onComplete(mockTask);
88+
credentialSignInHandler.onComplete(signInTask);
7489

7590
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
7691
ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
77-
verify(mockActivty).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
92+
verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
7893
Intent capturedIntent = intentCaptor.getValue();
7994
assertEquals(RC_SAVE_CREDENTIALS, (int) intCaptor.getValue());
8095
assertEquals(
@@ -93,24 +108,22 @@ public void testSignInSucceeded() {
93108

94109
@Test
95110
public void testSignInFailed_withFacebookAlreadyLinked() {
96-
Activity mockActivty = mock(Activity.class);
111+
Activity mockActivity = mock(Activity.class);
97112
ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
98113
FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class);
99-
IDPResponse mockIdpResponse = mock(IDPResponse.class);
114+
IDPResponse idpResponse = new IDPResponse(
115+
GoogleAuthProvider.PROVIDER_ID,
116+
TestConstants.EMAIL,
117+
new Bundle());
100118
CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(
101-
mockActivty,
119+
mockActivity,
102120
mockActivityHelper,
103121
RC_ACCOUNT_LINK,
104122
RC_SAVE_CREDENTIALS,
105-
mockIdpResponse);
123+
idpResponse);
106124

107125
Context mockContext = mock(Context.class);
108-
Task mockTask = mock(Task.class);
109126
FlowParameters mockFlowParams = mock(FlowParameters.class);
110-
// pretend there was already an account with this email
111-
when(mockTask.getException()).thenReturn(
112-
new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
113-
when(mockIdpResponse.getEmail()).thenReturn(TestConstants.EMAIL);
114127
when(mockActivityHelper.getFirebaseAuth()).thenReturn(mockFirebaseAuth);
115128
when(mockActivityHelper.getApplicationContext()).thenReturn(mockContext);
116129
when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams);
@@ -121,11 +134,13 @@ public void testSignInFailed_withFacebookAlreadyLinked() {
121134
new FakeProviderQueryResult(
122135
Arrays.asList(FacebookAuthProvider.PROVIDER_ID)), true, null));
123136

124-
125-
credentialSignInHandler.onComplete(mockTask);
137+
// pretend there was already an account with this email
138+
Task exceptionTask = Tasks.forException(
139+
new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
140+
credentialSignInHandler.onComplete(exceptionTask);
126141
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
127142
ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
128-
verify(mockActivty).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
143+
verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
129144
Intent capturedIntent = intentCaptor.getValue();
130145
assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
131146
assertEquals(
@@ -143,17 +158,19 @@ public void testSignInFailed_withFacebookAlreadyLinked() {
143158

144159
@Test
145160
public void testSignInFailed_withPasswordAccountAlreadyLinked() {
146-
Activity mockActivty = mock(Activity.class);
161+
Activity mockActivity = mock(Activity.class);
147162
ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
148163
FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class);
149-
IDPResponse mockIdpResponse = mock(IDPResponse.class);
150-
when(mockIdpResponse.getEmail()).thenReturn(TestConstants.EMAIL);
164+
IDPResponse idpResponse = new IDPResponse(
165+
GoogleAuthProvider.PROVIDER_ID,
166+
TestConstants.EMAIL,
167+
new Bundle());
151168
CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(
152-
mockActivty,
169+
mockActivity,
153170
mockActivityHelper,
154171
RC_ACCOUNT_LINK,
155172
RC_SAVE_CREDENTIALS,
156-
mockIdpResponse);
173+
idpResponse);
157174

158175
Context mockContext = mock(Context.class);
159176
Task mockTask = mock(Task.class);
@@ -162,7 +179,6 @@ public void testSignInFailed_withPasswordAccountAlreadyLinked() {
162179
// pretend there was already an account with this email
163180
when(mockTask.getException()).thenReturn(
164181
new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
165-
when(mockIdpResponse.getEmail()).thenReturn(TestConstants.EMAIL);
166182
when(mockActivityHelper.getFirebaseAuth()).thenReturn(mockFirebaseAuth);
167183
when(mockActivityHelper.getApplicationContext()).thenReturn(mockContext);
168184
when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams);
@@ -177,7 +193,7 @@ public void testSignInFailed_withPasswordAccountAlreadyLinked() {
177193
credentialSignInHandler.onComplete(mockTask);
178194
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
179195
ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
180-
verify(mockActivty).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
196+
verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
181197
Intent capturedIntent = intentCaptor.getValue();
182198
assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
183199
assertEquals(

0 commit comments

Comments
 (0)