diff --git a/firebase-inappmessaging-display/firebase-inappmessaging-display.gradle b/firebase-inappmessaging-display/firebase-inappmessaging-display.gradle index 7e1298e32ce..66451a1c15d 100644 --- a/firebase-inappmessaging-display/firebase-inappmessaging-display.gradle +++ b/firebase-inappmessaging-display/firebase-inappmessaging-display.gradle @@ -102,6 +102,9 @@ dependencies { testImplementation 'androidx.test:core:1.2.0' testImplementation 'com.google.guava:guava:30.1-android' + androidTestImplementation project(':integ-testing') + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation "androidx.annotation:annotation:1.0.0" androidTestImplementation "org.mockito:mockito-core:2.25.0" androidTestImplementation "com.google.dexmaker:dexmaker:1.2" androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:2.28.1" diff --git a/firebase-inappmessaging-display/src/androidTest/java/com/google/firebase/inappmessaging/display/StrictModeTest.java b/firebase-inappmessaging-display/src/androidTest/java/com/google/firebase/inappmessaging/display/StrictModeTest.java new file mode 100644 index 00000000000..ed17365f04c --- /dev/null +++ b/firebase-inappmessaging-display/src/androidTest/java/com/google/firebase/inappmessaging/display/StrictModeTest.java @@ -0,0 +1,47 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.firebase.inappmessaging.display; + +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.google.firebase.FirebaseApp; +import com.google.firebase.FirebaseOptions.Builder; +import com.google.firebase.iid.FirebaseInstanceId; +import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplay; +import com.google.firebase.testing.integ.StrictModeRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class StrictModeTest { + + @Rule public StrictModeRule strictMode = new StrictModeRule(); + + @Test + public void initializingFirebaseInAppMessagingDisplay_shouldNotViolateStrictMode() { + FirebaseApp app = + FirebaseApp.initializeApp( + ApplicationProvider.getApplicationContext(), + new Builder().setApiKey("api").setProjectId("123").setApplicationId("appId").build(), + "hello"); + // Don't check for violations in other erroring components + app.get(FirebaseInstanceId.class); + strictMode.runOnMainThread( + () -> { + app.get(FirebaseInAppMessagingDisplay.class); + }); + } +} diff --git a/firebase-inappmessaging/firebase-inappmessaging.gradle b/firebase-inappmessaging/firebase-inappmessaging.gradle index c41ed775b54..b77b49c78f9 100644 --- a/firebase-inappmessaging/firebase-inappmessaging.gradle +++ b/firebase-inappmessaging/firebase-inappmessaging.gradle @@ -144,10 +144,12 @@ dependencies { testImplementation 'com.google.guava:guava:30.1-android' testImplementation 'androidx.test:core:1.2.0' + androidTestImplementation project(':integ-testing') + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation "androidx.annotation:annotation:1.0.0" androidTestImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation "com.google.truth:truth:$googleTruthVersion" - androidTestImplementation 'org.mockito:mockito-core:2.25.0' androidTestImplementation 'org.awaitility:awaitility:3.1.0' androidTestImplementation "io.grpc:grpc-testing:$grpcVersion" androidTestImplementation 'com.linkedin.dexmaker:dexmaker:2.28.1' diff --git a/firebase-inappmessaging/src/androidTest/java/com/google/firebase/inappmessaging/StrictModeTest.java b/firebase-inappmessaging/src/androidTest/java/com/google/firebase/inappmessaging/StrictModeTest.java new file mode 100644 index 00000000000..c48618935b7 --- /dev/null +++ b/firebase-inappmessaging/src/androidTest/java/com/google/firebase/inappmessaging/StrictModeTest.java @@ -0,0 +1,47 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.firebase.inappmessaging; + +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.google.firebase.FirebaseApp; +import com.google.firebase.FirebaseOptions.Builder; +import com.google.firebase.testing.integ.StrictModeRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class StrictModeTest { + + @Rule public StrictModeRule strictMode = new StrictModeRule(); + + @Test + public void initializingFirebaseInAppMessaging_shouldNotViolateStrictMode() { + strictMode.runOnMainThread( + () -> { + FirebaseApp app = + FirebaseApp.initializeApp( + ApplicationProvider.getApplicationContext(), + new Builder() + .setApiKey("api") + .setProjectId("123") + .setApplicationId("appId") + .build(), + "hello"); + app.get(FirebaseInAppMessaging.class); + }); + } +}