Java Code Examples for com.google.firebase.FirebaseApp#clearInstancesForTest()

The following examples show how to use com.google.firebase.FirebaseApp#clearInstancesForTest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirebaseDynamicLinksImplTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  FirebaseApp.clearInstancesForTest();
  FirebaseOptions.Builder firebaseOptionsBuilder =
      new FirebaseOptions.Builder().setApplicationId("application_id").setApiKey("api_key");
  firebaseApp =
      FirebaseApp.initializeApp(RuntimeEnvironment.application, firebaseOptionsBuilder.build());
  // Create uri with properly escaped query params.
  updateAppUri =
      Uri.parse("market://details?id=com.google.android.gm&min_version=10")
          .buildUpon()
          .appendQueryParameter("url", "http://example.google.com")
          .build();
  api = new FirebaseDynamicLinksImpl(mockGoogleApi, mockAnalytics);
}
 
Example 2
Source File: PersistedInstallationTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  FirebaseApp.clearInstancesForTest();
  firebaseApp0 =
      FirebaseApp.initializeApp(
          ApplicationProvider.getApplicationContext(),
          new FirebaseOptions.Builder().setApplicationId(TEST_APP_ID_1).build());
  firebaseApp1 =
      FirebaseApp.initializeApp(
          ApplicationProvider.getApplicationContext(),
          new FirebaseOptions.Builder().setApplicationId(TEST_APP_ID_2).build(),
          "firebase_app_1");
  persistedInstallation0 = new PersistedInstallation(firebaseApp0);
  persistedInstallation1 = new PersistedInstallation(firebaseApp1);
}
 
Example 3
Source File: FirebaseInstallationsTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  FirebaseApp.clearInstancesForTest();
  executor = new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<>());

  firebaseApp =
      FirebaseApp.initializeApp(
          ApplicationProvider.getApplicationContext(),
          new FirebaseOptions.Builder()
              .setApplicationId(TEST_APP_ID_1)
              .setProjectId(TEST_PROJECT_ID)
              .setApiKey(TEST_API_KEY)
              .build());
  persistedInstallation = new PersistedInstallation(firebaseApp);
  persistedInstallation.clearForTesting();

  utils = new Utils();
  firebaseInstallations =
      new FirebaseInstallations(
          executor,
          firebaseApp,
          mockBackend,
          persistedInstallation,
          utils,
          mockIidStore,
          mockFidGenerator);

  when(mockFidGenerator.createRandomFid()).thenReturn(TEST_FID_1);
}
 
Example 4
Source File: DynamicLinkTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  FirebaseApp.clearInstancesForTest();
  FirebaseOptions.Builder firebaseOptionsBuilder =
      new FirebaseOptions.Builder().setApplicationId("application_id").setApiKey(API_KEY);
  FirebaseApp.initializeApp(RuntimeEnvironment.application, firebaseOptionsBuilder.build());

  builder = new Builder(mockFDLImpl);
  builder.setDynamicLinkDomain(DOMAIN);
}
 
Example 5
Source File: CustomInstallationIdCacheTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  FirebaseApp.clearInstancesForTest();
  firebaseApp0 =
      FirebaseApp.initializeApp(
          ApplicationProvider.getApplicationContext(),
          new FirebaseOptions.Builder().setApplicationId("1:123456789:android:abcdef").build());
  firebaseApp1 =
      FirebaseApp.initializeApp(
          ApplicationProvider.getApplicationContext(),
          new FirebaseOptions.Builder().setApplicationId("1:987654321:android:abcdef").build(),
          "firebase_app_1");
  cache0 = new CustomInstallationIdCache(firebaseApp0);
  cache1 = new CustomInstallationIdCache(firebaseApp1);
}
 
Example 6
Source File: FirebaseRemoteConfigIntegrationTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  DEFAULTS_MAP.put("first_default_key", "first_default_value");
  DEFAULTS_MAP.put("second_default_key", "second_default_value");
  DEFAULTS_MAP.put("third_default_key", "third_default_value");

  MockitoAnnotations.initMocks(this);
  Executor directExecutor = MoreExecutors.directExecutor();

  Context context = getInstrumentation().getTargetContext();
  FirebaseApp.clearInstancesForTest();
  FirebaseApp firebaseApp =
      FirebaseApp.initializeApp(
          context,
          new FirebaseOptions.Builder()
              .setApiKey(API_KEY)
              .setApplicationId(APP_ID)
              .setProjectId(PROJECT_ID)
              .build());

  // Catch all to avoid NPEs (the getters should never return null).
  when(mockFetchedCache.get()).thenReturn(Tasks.forResult(null));
  when(mockActivatedCache.get()).thenReturn(Tasks.forResult(null));
  when(mockFireperfFetchedCache.get()).thenReturn(Tasks.forResult(null));
  when(mockFireperfActivatedCache.get()).thenReturn(Tasks.forResult(null));

  frc =
      new FirebaseRemoteConfig(
          context,
          firebaseApp,
          mockFirebaseInstallations,
          mockFirebaseAbt,
          directExecutor,
          mockFetchedCache,
          mockActivatedCache,
          mockDefaultsCache,
          mockFetchHandler,
          mockGetHandler,
          metadataClient);
}
 
Example 7
Source File: FirebaseRemoteConfigTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
private static FirebaseApp initializeFirebaseApp(Context context) {
  FirebaseApp.clearInstancesForTest();

  return FirebaseApp.initializeApp(
      context,
      new FirebaseOptions.Builder()
          .setApiKey(API_KEY)
          .setApplicationId(APP_ID)
          .setProjectId(PROJECT_ID)
          .build());
}
 
Example 8
Source File: RemoteConfigComponentTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
private static FirebaseApp initializeFirebaseApp(Context context) {
  FirebaseApp.clearInstancesForTest();

  return FirebaseApp.initializeApp(
      context,
      new FirebaseOptions.Builder()
          .setApiKey(API_KEY)
          .setApplicationId(APP_ID)
          .setProjectId(PROJECT_ID)
          .build());
}
 
Example 9
Source File: FirebaseInstallationsRegistrarTest.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
  FirebaseApp.clearInstancesForTest();
}
 
Example 10
Source File: FirebaseAppRule.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
private void resetState() {
  FirebaseApp.clearInstancesForTest();
}
 
Example 11
Source File: StorageReferenceTest.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void badInitTest2() throws Exception {
  FirebaseApp.clearInstancesForTest();
  assertThrows(IllegalStateException.class, () -> FirebaseStorage.getInstance().getReference());
}
 
Example 12
Source File: FirebaseSegmentationTest.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  FirebaseApp.clearInstancesForTest();
  firebaseApp =
      FirebaseApp.initializeApp(
          ApplicationProvider.getApplicationContext(),
          new FirebaseOptions.Builder()
              .setApplicationId("1:123456789:android:abcdef")
              .setApiKey("api_key")
              .build());
  actualCache = new CustomInstallationIdCache(firebaseApp);

  when(backendClientReturnsOk.updateCustomInstallationId(
          anyLong(), anyString(), anyString(), anyString(), anyString()))
      .thenReturn(SegmentationServiceClient.Code.OK);
  when(backendClientReturnsOk.clearCustomInstallationId(
          anyLong(), anyString(), anyString(), anyString()))
      .thenReturn(SegmentationServiceClient.Code.OK);
  when(backendClientReturnsError.updateCustomInstallationId(
          anyLong(), anyString(), anyString(), anyString(), anyString()))
      .thenReturn(SegmentationServiceClient.Code.SERVER_ERROR);
  when(backendClientReturnsError.clearCustomInstallationId(
          anyLong(), anyString(), anyString(), anyString()))
      .thenReturn(SegmentationServiceClient.Code.SERVER_ERROR);
  when(firebaseInstallationsApi.getId()).thenReturn(Tasks.forResult(FIREBASE_INSTALLATION_ID));
  when(firebaseInstallationsApi.getToken(Mockito.anyBoolean()))
      .thenReturn(
          Tasks.forResult(
              new InstallationTokenResult() {
                @NonNull
                @Override
                public String getToken() {
                  return FIREBASE_INSTALLATION_ID_TOKEN;
                }

                @NonNull
                @Override
                public long getTokenExpirationTimestamp() {
                  return 0;
                }

                @NonNull
                @Override
                public long getTokenCreationTimestamp() {
                  return 0;
                }

                @NonNull
                @Override
                public Builder toBuilder() {
                  return null;
                }
              }));
  when(cacheReturnsError.insertOrUpdateCacheEntry(any())).thenReturn(false);
  when(cacheReturnsError.readCacheEntryValue()).thenReturn(null);

  taskExecutor = new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
}
 
Example 13
Source File: FirebaseSegmentationRegistrarTest.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
  FirebaseApp.clearInstancesForTest();
}