@Test public void testGetId_multipleCalls_sameFIDReturned() throws Exception { when(mockIidStore.readIid()).thenReturn(null); when(mockIidStore.readToken()).thenReturn(null); when(mockBackend.createFirebaseInstallation( anyString(), anyString(), anyString(), anyString(), any())) .thenReturn(TEST_INSTALLATION_RESPONSE); Task<String> task1 = firebaseInstallations.getId(); Task<String> task2 = firebaseInstallations.getId(); TestOnCompleteListener<String> onCompleteListener1 = new TestOnCompleteListener<>(); task1.addOnCompleteListener(executor, onCompleteListener1); TestOnCompleteListener<String> onCompleteListener2 = new TestOnCompleteListener<>(); task2.addOnCompleteListener(executor, onCompleteListener2); onCompleteListener1.await(); onCompleteListener2.await(); executor.awaitTermination(500, TimeUnit.MILLISECONDS); assertWithMessage("Persisted Fid of Task1 doesn't match.") .that(task1.getResult()) .isEqualTo(TEST_FID_1); assertWithMessage("Persisted Fid of Task2 doesn't match.") .that(task2.getResult()) .isEqualTo(TEST_FID_1); verify(mockBackend, times(1)) .createFirebaseInstallation(TEST_API_KEY, TEST_FID_1, TEST_PROJECT_ID, TEST_APP_ID_1, null); PersistedInstallationEntry entry = persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entry.getFirebaseInstallationId(), equalTo(TEST_FID_1)); assertTrue("the entry isn't doesn't have a registered fid: " + entry, entry.isRegistered()); }
@NonNull @Override public Task<String> getId() { preConditionChecks(); String fid = getCacheFid(); if (fid != null) { return Tasks.forResult(fid); } Task<String> task = addGetIdListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(false)); return task; }
FirebaseInstallations implements FirebaseInstallationsApi { @NonNull @Override public Task<String> getId() { preConditionChecks(); String fid = getCacheFid(); if (fid != null) { return Tasks.forResult(fid); } Task<String> task = addGetIdListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(false)); return task; } }
FirebaseInstallations implements FirebaseInstallationsApi { @NonNull @Override public Task<String> getId() { preConditionChecks(); String fid = getCacheFid(); if (fid != null) { return Tasks.forResult(fid); } Task<String> task = addGetIdListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(false)); return task; } FirebaseInstallations(
      FirebaseApp firebaseApp,
      @NonNull Provider<UserAgentPublisher> publisher,
      @NonNull Provider<HeartBeatInfo> heartbeatInfo);   FirebaseInstallations(
      ExecutorService backgroundExecutor,
      FirebaseApp firebaseApp,
      FirebaseInstallationServiceClient serviceClient,
      PersistedInstallation persistedInstallation,
      Utils utils,
      IidStore iidStore,
      RandomFidGenerator fidGenerator); }
FirebaseInstallations implements FirebaseInstallationsApi { @NonNull @Override public Task<String> getId() { preConditionChecks(); String fid = getCacheFid(); if (fid != null) { return Tasks.forResult(fid); } Task<String> task = addGetIdListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(false)); return task; } FirebaseInstallations(
      FirebaseApp firebaseApp,
      @NonNull Provider<UserAgentPublisher> publisher,
      @NonNull Provider<HeartBeatInfo> heartbeatInfo);   FirebaseInstallations(
      ExecutorService backgroundExecutor,
      FirebaseApp firebaseApp,
      FirebaseInstallationServiceClient serviceClient,
      PersistedInstallation persistedInstallation,
      Utils utils,
      IidStore iidStore,
      RandomFidGenerator fidGenerator); @NonNull static FirebaseInstallations getInstance(); @NonNull static FirebaseInstallations getInstance(@NonNull FirebaseApp app); @NonNull @Override Task<String> getId(); @NonNull @Override Task<InstallationTokenResult> getToken(boolean forceRefresh); @NonNull @Override Task<Void> delete(); }
FirebaseInstallations implements FirebaseInstallationsApi { @NonNull @Override public Task<String> getId() { preConditionChecks(); String fid = getCacheFid(); if (fid != null) { return Tasks.forResult(fid); } Task<String> task = addGetIdListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(false)); return task; } FirebaseInstallations(
      FirebaseApp firebaseApp,
      @NonNull Provider<UserAgentPublisher> publisher,
      @NonNull Provider<HeartBeatInfo> heartbeatInfo);   FirebaseInstallations(
      ExecutorService backgroundExecutor,
      FirebaseApp firebaseApp,
      FirebaseInstallationServiceClient serviceClient,
      PersistedInstallation persistedInstallation,
      Utils utils,
      IidStore iidStore,
      RandomFidGenerator fidGenerator); @NonNull static FirebaseInstallations getInstance(); @NonNull static FirebaseInstallations getInstance(@NonNull FirebaseApp app); @NonNull @Override Task<String> getId(); @NonNull @Override Task<InstallationTokenResult> getToken(boolean forceRefresh); @NonNull @Override Task<Void> delete();  }