3333import com .google .api .client .testing .http .MockHttpTransport ;
3434import com .google .api .client .testing .http .MockLowLevelHttpResponse ;
3535import com .google .auth .oauth2 .GoogleCredentials ;
36+ import com .google .common .base .Supplier ;
3637import com .google .common .collect .ImmutableList ;
3738import com .google .common .collect .ImmutableMap ;
3839import com .google .common .collect .Iterables ;
@@ -550,14 +551,7 @@ public void call(FirebaseAuth auth) throws Exception {
550551 .build ();
551552
552553 MockLowLevelHttpResponse response = new MockLowLevelHttpResponse ();
553- MockHttpTransport transport = new MockHttpTransport .Builder ()
554- .setLowLevelHttpResponse (response )
555- .build ();
556- FirebaseApp .initializeApp (new FirebaseOptions .Builder ()
557- .setCredentials (credentials )
558- .setProjectId ("test-project-id" )
559- .setHttpTransport (transport )
560- .build ());
554+ FirebaseAuth auth = getRetryDisabledAuth (response );
561555
562556 // Test for common HTTP error codes
563557 for (int code : ImmutableList .of (302 , 400 , 401 , 404 , 500 )) {
@@ -566,7 +560,7 @@ public void call(FirebaseAuth auth) throws Exception {
566560 response .setContent ("{}" );
567561 response .setStatusCode (code );
568562 try {
569- operation .call (FirebaseAuth . getInstance () );
563+ operation .call (auth );
570564 fail ("No error thrown for HTTP error: " + code );
571565 } catch (ExecutionException e ) {
572566 assertTrue (e .getCause () instanceof FirebaseAuthException );
@@ -584,7 +578,7 @@ public void call(FirebaseAuth auth) throws Exception {
584578 response .setContent ("{\" error\" : {\" message\" : \" USER_NOT_FOUND\" }}" );
585579 response .setStatusCode (500 );
586580 try {
587- operation .call (FirebaseAuth . getInstance () );
581+ operation .call (auth );
588582 fail ("No error thrown for HTTP error" );
589583 } catch (ExecutionException e ) {
590584 assertTrue (e .getCause ().toString (), e .getCause () instanceof FirebaseAuthException );
@@ -615,16 +609,9 @@ public void testGetUserUnexpectedHttpError() throws Exception {
615609 MockLowLevelHttpResponse response = new MockLowLevelHttpResponse ();
616610 response .setContent ("{\" not\" json}" );
617611 response .setStatusCode (500 );
618- MockHttpTransport transport = new MockHttpTransport .Builder ()
619- .setLowLevelHttpResponse (response )
620- .build ();
621- FirebaseApp .initializeApp (new FirebaseOptions .Builder ()
622- .setCredentials (credentials )
623- .setProjectId ("test-project-id" )
624- .setHttpTransport (transport )
625- .build ());
612+ FirebaseAuth auth = getRetryDisabledAuth (response );
626613 try {
627- FirebaseAuth . getInstance () .getUserAsync ("testuser" ).get ();
614+ auth .getUserAsync ("testuser" ).get ();
628615 fail ("No error thrown for JSON error" );
629616 } catch (ExecutionException e ) {
630617 assertTrue (e .getCause () instanceof FirebaseAuthException );
@@ -1173,15 +1160,10 @@ public void testGenerateSignInWithEmailLinkWithSettings() throws Exception {
11731160
11741161 @ Test
11751162 public void testHttpErrorWithCode () {
1176- FirebaseApp .initializeApp (new FirebaseOptions .Builder ()
1177- .setCredentials (credentials )
1178- .setHttpTransport (new MultiRequestMockHttpTransport (ImmutableList .of (
1179- new MockLowLevelHttpResponse ()
1180- .setContent ("{\" error\" : {\" message\" : \" UNAUTHORIZED_DOMAIN\" }}" )
1181- .setStatusCode (500 ))))
1182- .setProjectId ("test-project-id" )
1183- .build ());
1184- FirebaseAuth auth = FirebaseAuth .getInstance ();
1163+ MockLowLevelHttpResponse response = new MockLowLevelHttpResponse ()
1164+ .setContent ("{\" error\" : {\" message\" : \" UNAUTHORIZED_DOMAIN\" }}" )
1165+ .setStatusCode (500 );
1166+ FirebaseAuth auth = getRetryDisabledAuth (response );
11851167 FirebaseUserManager userManager = auth .getUserManager ();
11861168 try {
11871169 userManager .getEmailActionLink (EmailLinkType .PASSWORD_RESET , "test@example.com" , null );
@@ -1194,15 +1176,10 @@ public void testHttpErrorWithCode() {
11941176
11951177 @ Test
11961178 public void testUnexpectedHttpError () {
1197- FirebaseApp .initializeApp (new FirebaseOptions .Builder ()
1198- .setCredentials (credentials )
1199- .setHttpTransport (new MultiRequestMockHttpTransport (ImmutableList .of (
1200- new MockLowLevelHttpResponse ()
1201- .setContent ("{}" )
1202- .setStatusCode (500 ))))
1203- .setProjectId ("test-project-id" )
1204- .build ());
1205- FirebaseAuth auth = FirebaseAuth .getInstance ();
1179+ MockLowLevelHttpResponse response = new MockLowLevelHttpResponse ()
1180+ .setContent ("{}" )
1181+ .setStatusCode (500 );
1182+ FirebaseAuth auth = getRetryDisabledAuth (response );
12061183 FirebaseUserManager userManager = auth .getUserManager ();
12071184 try {
12081185 userManager .getEmailActionLink (EmailLinkType .PASSWORD_RESET , "test@example.com" , null );
@@ -1231,6 +1208,26 @@ private static TestResponseInterceptor initializeAppForUserManagement(String ...
12311208 return interceptor ;
12321209 }
12331210
1211+ private static FirebaseAuth getRetryDisabledAuth (MockLowLevelHttpResponse response ) {
1212+ final MockHttpTransport transport = new MockHttpTransport .Builder ()
1213+ .setLowLevelHttpResponse (response )
1214+ .build ();
1215+ final FirebaseApp app = FirebaseApp .initializeApp (new FirebaseOptions .Builder ()
1216+ .setCredentials (credentials )
1217+ .setProjectId ("test-project-id" )
1218+ .setHttpTransport (transport )
1219+ .build ());
1220+ return FirebaseAuth .builder ()
1221+ .setFirebaseApp (app )
1222+ .setUserManager (new Supplier <FirebaseUserManager >() {
1223+ @ Override
1224+ public FirebaseUserManager get () {
1225+ return new FirebaseUserManager (app , transport .createRequestFactory ());
1226+ }
1227+ })
1228+ .build ();
1229+ }
1230+
12341231 private static void checkUserRecord (UserRecord userRecord ) {
12351232 assertEquals ("testuser" , userRecord .getUid ());
12361233 assertEquals ("testuser@example.com" , userRecord .getEmail ());
0 commit comments