@@ -92,7 +92,7 @@ public class FirebaseInstallationsInstrumentedTest {
92
92
.setFirebaseInstallationId (TEST_FID_1 )
93
93
.setAuthToken (TEST_AUTH_TOKEN )
94
94
.setRefreshToken (TEST_REFRESH_TOKEN )
95
- .setTokenCreationEpochInSecs (TEST_CREATION_TIMESTAMP_1 )
95
+ .setTokenCreationEpochInSecs (TEST_CREATION_TIMESTAMP_2 )
96
96
.setExpiresInSecs (TEST_TOKEN_EXPIRATION_TIMESTAMP )
97
97
.setRegistrationStatus (PersistedFid .RegistrationStatus .REGISTERED )
98
98
.build ();
@@ -117,6 +117,16 @@ public class FirebaseInstallationsInstrumentedTest {
117
117
.setRegistrationStatus (PersistedFid .RegistrationStatus .UNREGISTERED )
118
118
.build ();
119
119
120
+ private static final PersistedFidEntry UPDATED_AUTH_TOKEN_ENTRY =
121
+ PersistedFidEntry .builder ()
122
+ .setFirebaseInstallationId (TEST_FID_1 )
123
+ .setAuthToken (TEST_AUTH_TOKEN_2 )
124
+ .setRefreshToken (TEST_REFRESH_TOKEN )
125
+ .setTokenCreationEpochInSecs (TEST_CREATION_TIMESTAMP_2 )
126
+ .setExpiresInSecs (TEST_TOKEN_EXPIRATION_TIMESTAMP )
127
+ .setRegistrationStatus (PersistedFid .RegistrationStatus .REGISTERED )
128
+ .build ();
129
+
120
130
@ Before
121
131
public void setUp () throws FirebaseInstallationServiceException {
122
132
MockitoAnnotations .initMocks (this );
@@ -152,7 +162,6 @@ public void setUp() throws FirebaseInstallationServiceException {
152
162
153
163
when (mockUtils .createRandomFid ()).thenReturn (TEST_FID_1 );
154
164
when (mockUtils .currentTimeInSecs ()).thenReturn (TEST_CREATION_TIMESTAMP_2 );
155
- when (mockUtils .isAuthTokenExpired (any ())).thenReturn (false );
156
165
157
166
// Mocks success on FIS deletion
158
167
doNothing ()
@@ -173,6 +182,7 @@ public void cleanUp() throws Exception {
173
182
174
183
@ Test
175
184
public void testGetId_PersistedFidOk_BackendOk () throws Exception {
185
+ when (mockUtils .isAuthTokenExpired (REGISTERED_FID_ENTRY )).thenReturn (false );
176
186
FirebaseInstallations firebaseInstallations =
177
187
new FirebaseInstallations (
178
188
executor , firebaseApp , backendClientReturnsOk , persistedFid , mockUtils );
@@ -194,6 +204,7 @@ public void testGetId_PersistedFidOk_BackendOk() throws Exception {
194
204
195
205
@ Test
196
206
public void testGetId_multipleCalls_sameFIDReturned () throws Exception {
207
+ when (mockUtils .isAuthTokenExpired (REGISTERED_FID_ENTRY )).thenReturn (false );
197
208
FirebaseInstallations firebaseInstallations =
198
209
new FirebaseInstallations (
199
210
executor , firebaseApp , backendClientReturnsOk , persistedFid , mockUtils );
@@ -266,6 +277,7 @@ public void testGetId_fidRegistrationUncheckedException_statusUpdated() throws E
266
277
invocation -> {
267
278
throw new InterruptedException ();
268
279
});
280
+ when (mockUtils .isAuthTokenExpired (REGISTERED_FID_ENTRY )).thenReturn (false );
269
281
270
282
FirebaseInstallations firebaseInstallations =
271
283
new FirebaseInstallations (executor , firebaseApp , mockClient , persistedFid , mockUtils );
@@ -294,7 +306,7 @@ public void testGetId_expiredAuthTokenUncheckedException_statusUpdated() throws
294
306
invocation -> {
295
307
throw new InterruptedException ();
296
308
});
297
- when (mockUtils .isAuthTokenExpired (any () )).thenReturn (true );
309
+ when (mockUtils .isAuthTokenExpired (EXPIRED_AUTH_TOKEN_ENTRY )).thenReturn (true );
298
310
299
311
FirebaseInstallations firebaseInstallations =
300
312
new FirebaseInstallations (executor , firebaseApp , mockClient , persistedFid , mockUtils );
@@ -316,9 +328,10 @@ public void testGetId_expiredAuthTokenUncheckedException_statusUpdated() throws
316
328
317
329
@ Test
318
330
public void testGetId_expiredAuthToken_refreshesAuthToken () throws Exception {
319
- when (mockUtils .isAuthTokenExpired (any ())).thenReturn (true );
320
331
// Update local storage with fid entry that has auth token expired.
321
332
persistedFid .insertOrUpdatePersistedFidEntry (EXPIRED_AUTH_TOKEN_ENTRY );
333
+ when (mockUtils .isAuthTokenExpired (EXPIRED_AUTH_TOKEN_ENTRY )).thenReturn (true );
334
+
322
335
FirebaseInstallations firebaseInstallations =
323
336
new FirebaseInstallations (
324
337
executor , firebaseApp , backendClientReturnsOk , persistedFid , mockUtils );
@@ -343,6 +356,7 @@ public void testGetId_expiredAuthToken_refreshesAuthToken() throws Exception {
343
356
344
357
@ Test
345
358
public void testGetAuthToken_fidDoesNotExist_successful () throws Exception {
359
+ when (mockUtils .isAuthTokenExpired (REGISTERED_FID_ENTRY )).thenReturn (false );
346
360
FirebaseInstallations firebaseInstallations =
347
361
new FirebaseInstallations (
348
362
executor , firebaseApp , backendClientReturnsOk , persistedFid , mockUtils );
@@ -355,6 +369,7 @@ public void testGetAuthToken_fidDoesNotExist_successful() throws Exception {
355
369
356
370
@ Test
357
371
public void testGetAuthToken_PersistedFidError_failure () throws Exception {
372
+ when (mockUtils .isAuthTokenExpired (REGISTERED_FID_ENTRY )).thenReturn (false );
358
373
FirebaseInstallations firebaseInstallations =
359
374
new FirebaseInstallations (
360
375
executor , firebaseApp , backendClientReturnsOk , persistedFidReturnsError , mockUtils );
@@ -378,6 +393,8 @@ public void testGetAuthToken_PersistedFidError_failure() throws Exception {
378
393
@ Test
379
394
public void testGetAuthToken_fidExists_successful () throws Exception {
380
395
when (mockPersistedFid .readPersistedFidEntryValue ()).thenReturn (REGISTERED_FID_ENTRY );
396
+ when (mockUtils .isAuthTokenExpired (REGISTERED_FID_ENTRY )).thenReturn (false );
397
+
381
398
FirebaseInstallations firebaseInstallations =
382
399
new FirebaseInstallations (
383
400
executor , firebaseApp , backendClientReturnsOk , mockPersistedFid , mockUtils );
@@ -395,8 +412,10 @@ public void testGetAuthToken_fidExists_successful() throws Exception {
395
412
396
413
@ Test
397
414
public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS () throws Exception {
398
- when (mockUtils .isAuthTokenExpired (any ())).thenReturn (true , true , false );
399
415
persistedFid .insertOrUpdatePersistedFidEntry (EXPIRED_AUTH_TOKEN_ENTRY );
416
+ when (mockUtils .isAuthTokenExpired (EXPIRED_AUTH_TOKEN_ENTRY )).thenReturn (true );
417
+ when (mockUtils .isAuthTokenExpired (UPDATED_AUTH_TOKEN_ENTRY )).thenReturn (false );
418
+
400
419
FirebaseInstallations firebaseInstallations =
401
420
new FirebaseInstallations (
402
421
executor , firebaseApp , backendClientReturnsOk , persistedFid , mockUtils );
@@ -417,6 +436,8 @@ public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exc
417
436
// Update local storage with a unregistered fid entry to validate that getAuthToken calls getId
418
437
// to ensure FID registration and returns a valid auth token.
419
438
persistedFid .insertOrUpdatePersistedFidEntry (UNREGISTERED_FID_ENTRY );
439
+ when (mockUtils .isAuthTokenExpired (REGISTERED_FID_ENTRY )).thenReturn (false );
440
+
420
441
FirebaseInstallations firebaseInstallations =
421
442
new FirebaseInstallations (
422
443
executor , firebaseApp , backendClientReturnsOk , persistedFid , mockUtils );
@@ -440,6 +461,8 @@ public void testGetAuthToken_serverError_failure() throws Exception {
440
461
.thenThrow (
441
462
new FirebaseInstallationServiceException (
442
463
"Server Error" , FirebaseInstallationServiceException .Status .SERVER_ERROR ));
464
+ when (mockUtils .isAuthTokenExpired (REGISTERED_FID_ENTRY )).thenReturn (false );
465
+
443
466
FirebaseInstallations firebaseInstallations =
444
467
new FirebaseInstallations (
445
468
executor , firebaseApp , backendClientReturnsError , mockPersistedFid , mockUtils );
@@ -466,7 +489,9 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce(
466
489
// triggered simultaneously. Task2 waits for Task1 to complete. On task1 completion, task2 reads
467
490
// the UPDATED_AUTH_TOKEN_FID_ENTRY generated by Task1.
468
491
persistedFid .insertOrUpdatePersistedFidEntry (EXPIRED_AUTH_TOKEN_ENTRY );
469
- when (mockUtils .isAuthTokenExpired (any ())).thenReturn (true , true , true , false );
492
+ when (mockUtils .isAuthTokenExpired (EXPIRED_AUTH_TOKEN_ENTRY )).thenReturn (true );
493
+ when (mockUtils .isAuthTokenExpired (UPDATED_AUTH_TOKEN_ENTRY )).thenReturn (false );
494
+
470
495
FirebaseInstallations firebaseInstallations =
471
496
new FirebaseInstallations (
472
497
executor , firebaseApp , backendClientReturnsOk , persistedFid , mockUtils );
@@ -514,6 +539,7 @@ public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() th
514
539
.build ()))
515
540
.when (backendClientReturnsOk )
516
541
.generateAuthToken (anyString (), anyString (), anyString (), anyString ());
542
+ when (mockUtils .isAuthTokenExpired (any ())).thenReturn (false );
517
543
518
544
FirebaseInstallations firebaseInstallations =
519
545
new FirebaseInstallations (
0 commit comments