|
| 1 | +// Copyright 2019 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package com.google.firebase.segmentation; |
| 16 | + |
| 17 | +import static org.junit.Assert.assertNotNull; |
| 18 | +import static org.junit.Assert.assertNull; |
| 19 | + |
| 20 | +import androidx.test.core.app.ApplicationProvider; |
| 21 | +import com.google.firebase.FirebaseApp; |
| 22 | +import com.google.firebase.FirebaseOptions; |
| 23 | +import org.junit.Before; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | +import org.robolectric.RobolectricTestRunner; |
| 27 | + |
| 28 | +@RunWith(RobolectricTestRunner.class) |
| 29 | +public class FirebaseSegmentationRegistrarTest { |
| 30 | + |
| 31 | + @Before |
| 32 | + public void setUp() { |
| 33 | + FirebaseApp.clearInstancesForTest(); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void getFirebaseInstallationsInstance() { |
| 38 | + FirebaseApp defaultApp = |
| 39 | + FirebaseApp.initializeApp( |
| 40 | + ApplicationProvider.getApplicationContext(), |
| 41 | + new FirebaseOptions.Builder().setApplicationId("1:123456789:android:abcdef").build()); |
| 42 | + |
| 43 | + FirebaseApp anotherApp = |
| 44 | + FirebaseApp.initializeApp( |
| 45 | + ApplicationProvider.getApplicationContext(), |
| 46 | + new FirebaseOptions.Builder().setApplicationId("1:987654321:android:abcdef").build(), |
| 47 | + "firebase_app_1"); |
| 48 | + |
| 49 | + FirebaseSegmentation defaultSegmentation = FirebaseSegmentation.getInstance(); |
| 50 | + assertNotNull(defaultSegmentation); |
| 51 | + assertNull(defaultSegmentation.setCustomInstallationId("12345").getResult()); |
| 52 | + |
| 53 | + FirebaseSegmentation anotherSegmentation = FirebaseSegmentation.getInstance(anotherApp); |
| 54 | + assertNotNull(anotherSegmentation); |
| 55 | + assertNull(anotherSegmentation.setCustomInstallationId("ghdjaas").getResult()); |
| 56 | + } |
| 57 | +} |
0 commit comments