|
| 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.inappmessaging.display.ktx |
| 16 | + |
| 17 | +import com.google.common.truth.Truth.assertThat |
| 18 | +import com.google.firebase.FirebaseApp |
| 19 | +import com.google.firebase.FirebaseOptions |
| 20 | +import com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay |
| 21 | +import com.google.firebase.ktx.Firebase |
| 22 | +import com.google.firebase.ktx.app |
| 23 | +import com.google.firebase.ktx.initialize |
| 24 | +import com.google.firebase.platforminfo.UserAgentPublisher |
| 25 | +import org.junit.After |
| 26 | +import org.junit.Before |
| 27 | +import org.junit.Test |
| 28 | +import org.junit.runner.RunWith |
| 29 | +import org.robolectric.RobolectricTestRunner |
| 30 | +import org.robolectric.RuntimeEnvironment |
| 31 | + |
| 32 | +const val APP_ID = "APP_ID" |
| 33 | +const val API_KEY = "API_KEY" |
| 34 | + |
| 35 | +const val EXISTING_APP = "existing" |
| 36 | + |
| 37 | +abstract class BaseTestCase { |
| 38 | + @Before |
| 39 | + fun setUp() { |
| 40 | + Firebase.initialize( |
| 41 | + RuntimeEnvironment.application, |
| 42 | + FirebaseOptions.Builder() |
| 43 | + .setApplicationId(APP_ID) |
| 44 | + .setApiKey(API_KEY) |
| 45 | + .setProjectId("123") |
| 46 | + .build() |
| 47 | + ) |
| 48 | + |
| 49 | + Firebase.initialize( |
| 50 | + RuntimeEnvironment.application, |
| 51 | + FirebaseOptions.Builder() |
| 52 | + .setApplicationId(APP_ID) |
| 53 | + .setApiKey(API_KEY) |
| 54 | + .setProjectId("123") |
| 55 | + .build(), |
| 56 | + EXISTING_APP |
| 57 | + ) |
| 58 | + } |
| 59 | + |
| 60 | + @After |
| 61 | + fun cleanUp() { |
| 62 | + FirebaseApp.clearInstancesForTest() |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +@RunWith(RobolectricTestRunner::class) |
| 67 | +class InAppMessagingDisplayTests : BaseTestCase() { |
| 68 | + |
| 69 | + @Test |
| 70 | + fun `inAppMessagingDisplay should delegate to FirebaseInAppMessagingDisplay#getInstance()`() { |
| 71 | + assertThat(Firebase.inAppMessagingDisplay).isSameInstanceAs(FirebaseInAppMessagingDisplay.getInstance()) |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +@RunWith(RobolectricTestRunner::class) |
| 76 | +class LibraryVersionTest : BaseTestCase() { |
| 77 | + @Test |
| 78 | + fun `library version should be registered with runtime`() { |
| 79 | + val publisher = Firebase.app.get(UserAgentPublisher::class.java) |
| 80 | + assertThat(publisher.userAgent).contains(LIBRARY_NAME) |
| 81 | + } |
| 82 | +} |
0 commit comments