Skip to content

Commit 3adccda

Browse files
authored
Renaming getAuthToken to getToken. (#1026)
1 parent 101ee18 commit 3adccda

File tree

5 files changed

+28
-33
lines changed

5 files changed

+28
-33
lines changed

firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public interface FirebaseInstallationsApi {
3939
int DO_NOT_FORCE_REFRESH = 0;
4040
/**
4141
* AuthToken is forcefully refreshed on calling the {@link
42-
* FirebaseInstallationsApi#getAuthToken(int)}.
42+
* FirebaseInstallationsApi#getToken(int)}.
4343
*/
4444
int FORCE_REFRESH = 1;
4545

@@ -50,7 +50,7 @@ public interface FirebaseInstallationsApi {
5050
Task<String> getId();
5151

5252
/** Async function that returns a auth token(public key) of this Firebase app installation. */
53-
Task<InstallationTokenResult> getAuthToken(@AuthTokenOption int authTokenOption);
53+
Task<InstallationTokenResult> getToken(@AuthTokenOption int authTokenOption);
5454

5555
/**
5656
* Async function that deletes this Firebase app installation from Firebase backend. This call

firebase-installations/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package com.google.firebase.installations {
33

44
public class FirebaseInstallations {
55
method @NonNull public Task<Void> delete();
6-
method @NonNull public Task<InstallationTokenResult> getAuthToken(int);
76
method @NonNull public Task<String> getId();
87
method @NonNull public static com.google.firebase.installations.FirebaseInstallations getInstance();
98
method @NonNull public static com.google.firebase.installations.FirebaseInstallations getInstance(@NonNull FirebaseApp);
9+
method @NonNull public Task<InstallationTokenResult> getToken(int);
1010
}
1111

1212
public class FirebaseInstallationsException {

firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public void testGetAuthToken_fidDoesNotExist_successful() throws Exception {
489489
when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(/*isValid*/ false);
490490
FirebaseInstallations firebaseInstallations = getFirebaseInstallations();
491491

492-
Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
492+
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
493493

494494
PersistedInstallationEntry entryValue =
495495
persistedInstallation.readPersistedInstallationEntryValue();
@@ -510,8 +510,7 @@ public void testGetAuthToken_PersistedInstallationError_failure() throws Excepti
510510

511511
// Expect exception
512512
try {
513-
Tasks.await(
514-
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
513+
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
515514
fail("Could not update local storage.");
516515
} catch (ExecutionException expected) {
517516
assertWithMessage("Exception class doesn't match")
@@ -540,8 +539,7 @@ public void testGetAuthToken_fidExists_successful() throws Exception {
540539
mockIidStore);
541540

542541
InstallationTokenResult installationTokenResult =
543-
Tasks.await(
544-
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
542+
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
545543

546544
assertWithMessage("Persisted Auth Token doesn't match")
547545
.that(installationTokenResult.getToken())
@@ -551,16 +549,15 @@ public void testGetAuthToken_fidExists_successful() throws Exception {
551549
}
552550

553551
@Test
554-
public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Exception {
552+
public void testGetToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Exception {
555553
persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY);
556554
when(mockUtils.isAuthTokenExpired(EXPIRED_AUTH_TOKEN_ENTRY)).thenReturn(/*isExpired*/ true);
557555
when(mockUtils.isAuthTokenExpired(UPDATED_AUTH_TOKEN_ENTRY)).thenReturn(/*isValid*/ false);
558556

559557
FirebaseInstallations firebaseInstallations = getFirebaseInstallations();
560558

561559
InstallationTokenResult installationTokenResult =
562-
Tasks.await(
563-
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
560+
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
564561

565562
assertWithMessage("Persisted Auth Token doesn't match")
566563
.that(installationTokenResult.getToken())
@@ -570,17 +567,16 @@ public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Ex
570567
}
571568

572569
@Test
573-
public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exception {
574-
// Update local storage with a unregistered installation entry to validate that getAuthToken
570+
public void testGetToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exception {
571+
// Update local storage with a unregistered installation entry to validate that getToken
575572
// calls getId to ensure FID registration and returns a valid auth token.
576573
persistedInstallation.insertOrUpdatePersistedInstallationEntry(UNREGISTERED_INSTALLATION_ENTRY);
577574
when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(/*isValid*/ false);
578575

579576
FirebaseInstallations firebaseInstallations = getFirebaseInstallations();
580577

581578
InstallationTokenResult installationTokenResult =
582-
Tasks.await(
583-
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
579+
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
584580

585581
assertWithMessage("Persisted Auth Token doesn't match")
586582
.that(installationTokenResult.getToken())
@@ -590,7 +586,7 @@ public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exc
590586
}
591587

592588
@Test
593-
public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exception {
589+
public void testGetToken_fidError_persistedInstallationCleared() throws Exception {
594590
// Update local storage with an expired installation entry to ensure that generate auth token
595591
// is called.
596592
persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY);
@@ -606,8 +602,8 @@ public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exce
606602

607603
// Expect exception
608604
try {
609-
Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH));
610-
fail("getAuthToken() failed due to Server Error.");
605+
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH));
606+
fail("getToken() failed due to Server Error.");
611607
} catch (ExecutionException expected) {
612608
assertWithMessage("Exception class doesn't match")
613609
.that(expected)
@@ -626,7 +622,7 @@ public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exce
626622
}
627623

628624
@Test
629-
public void testGetAuthToken_serverError_failure() throws Exception {
625+
public void testGetToken_serverError_failure() throws Exception {
630626
when(mockPersistedInstallation.readPersistedInstallationEntryValue())
631627
.thenReturn(REGISTERED_INSTALLATION_ENTRY);
632628
when(backendClientReturnsError.generateAuthToken(
@@ -645,8 +641,8 @@ public void testGetAuthToken_serverError_failure() throws Exception {
645641

646642
// Expect exception
647643
try {
648-
Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH));
649-
fail("getAuthToken() failed due to Server Error.");
644+
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH));
645+
fail("getToken() failed due to Server Error.");
650646
} catch (ExecutionException expected) {
651647
assertWithMessage("Exception class doesn't match")
652648
.that(expected)
@@ -659,8 +655,7 @@ public void testGetAuthToken_serverError_failure() throws Exception {
659655
}
660656

661657
@Test
662-
public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce()
663-
throws Exception {
658+
public void testGetToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce() throws Exception {
664659
// Update local storage with a EXPIRED_AUTH_TOKEN_ENTRY to validate the flow of multiple tasks
665660
// triggered simultaneously. Task2 waits for Task1 to complete. On task1 completion, task2 reads
666661
// the UPDATED_AUTH_TOKEN_FID_ENTRY generated by Task1.
@@ -670,11 +665,11 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce(
670665

671666
FirebaseInstallations firebaseInstallations = getFirebaseInstallations();
672667

673-
// Call getAuthToken multiple times with DO_NOT_FORCE_REFRESH option
668+
// Call getToken multiple times with DO_NOT_FORCE_REFRESH option
674669
Task<InstallationTokenResult> task1 =
675-
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH);
670+
firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH);
676671
Task<InstallationTokenResult> task2 =
677-
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH);
672+
firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH);
678673

679674
Tasks.await(Tasks.whenAllComplete(task1, task2));
680675

@@ -689,10 +684,10 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce(
689684
}
690685

691686
@Test
692-
public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() throws Exception {
687+
public void testGetToken_multipleCallsForceRefresh_fetchedNewTokenTwice() throws Exception {
693688
persistedInstallation.insertOrUpdatePersistedInstallationEntry(REGISTERED_INSTALLATION_ENTRY);
694689
// Use a mock ServiceClient for network calls with delay(500ms) to ensure first task is not
695-
// completed before the second task starts. Hence, we can test multiple calls to getAuthToken()
690+
// completed before the second task starts. Hence, we can test multiple calls to getToken()
696691
// and verify one task waits for another task to complete.
697692

698693
doAnswer(
@@ -719,11 +714,11 @@ public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() th
719714

720715
FirebaseInstallations firebaseInstallations = getFirebaseInstallations();
721716

722-
// Call getAuthToken multiple times with FORCE_REFRESH option.
717+
// Call getToken multiple times with FORCE_REFRESH option.
723718
Task<InstallationTokenResult> task1 =
724-
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH);
719+
firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH);
725720
Task<InstallationTokenResult> task2 =
726-
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH);
721+
firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH);
727722
Tasks.await(Tasks.whenAllComplete(task1, task2));
728723

729724
// As we cannot ensure which task got executed first, verifying with both expected values

firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void hasFid(String fid) {
6363
}
6464

6565
public void hasAuthToken(String authToken) {
66-
check("getAuthToken()").that(actual.getAuthToken()).isEqualTo(authToken);
66+
check("getToken()").that(actual.getAuthToken()).isEqualTo(authToken);
6767
}
6868

6969
public void hasRefreshToken(String refreshToken) {

firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public Task<String> getId() {
151151
*/
152152
@NonNull
153153
@Override
154-
public Task<InstallationTokenResult> getAuthToken(@AuthTokenOption int authTokenOption) {
154+
public Task<InstallationTokenResult> getToken(@AuthTokenOption int authTokenOption) {
155155
Task<InstallationTokenResult> task = addGetAuthTokenListener(authTokenOption);
156156
executor.execute(this::doRegistration);
157157
return task;

0 commit comments

Comments
 (0)