Skip to content

Commit b2cbd70

Browse files
authored
Add strict mode tests to inappmessaging and inappmessaging-display (#4136)
1 parent 3bf2c19 commit b2cbd70

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

firebase-inappmessaging-display/firebase-inappmessaging-display.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ dependencies {
102102
testImplementation 'androidx.test:core:1.2.0'
103103
testImplementation 'com.google.guava:guava:30.1-android'
104104

105+
androidTestImplementation project(':integ-testing')
106+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
107+
androidTestImplementation "androidx.annotation:annotation:1.0.0"
105108
androidTestImplementation "org.mockito:mockito-core:2.25.0"
106109
androidTestImplementation "com.google.dexmaker:dexmaker:1.2"
107110
androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:2.28.1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2020 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;
16+
17+
import androidx.test.core.app.ApplicationProvider;
18+
import androidx.test.ext.junit.runners.AndroidJUnit4;
19+
import com.google.firebase.FirebaseApp;
20+
import com.google.firebase.FirebaseOptions.Builder;
21+
import com.google.firebase.iid.FirebaseInstanceId;
22+
import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplay;
23+
import com.google.firebase.testing.integ.StrictModeRule;
24+
import org.junit.Rule;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
28+
@RunWith(AndroidJUnit4.class)
29+
public class StrictModeTest {
30+
31+
@Rule public StrictModeRule strictMode = new StrictModeRule();
32+
33+
@Test
34+
public void initializingFirebaseInAppMessagingDisplay_shouldNotViolateStrictMode() {
35+
FirebaseApp app =
36+
FirebaseApp.initializeApp(
37+
ApplicationProvider.getApplicationContext(),
38+
new Builder().setApiKey("api").setProjectId("123").setApplicationId("appId").build(),
39+
"hello");
40+
// Don't check for violations in other erroring components
41+
app.get(FirebaseInstanceId.class);
42+
strictMode.runOnMainThread(
43+
() -> {
44+
app.get(FirebaseInAppMessagingDisplay.class);
45+
});
46+
}
47+
}

firebase-inappmessaging/firebase-inappmessaging.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ dependencies {
144144
testImplementation 'com.google.guava:guava:30.1-android'
145145
testImplementation 'androidx.test:core:1.2.0'
146146

147+
androidTestImplementation project(':integ-testing')
148+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
149+
androidTestImplementation "androidx.annotation:annotation:1.0.0"
147150
androidTestImplementation 'junit:junit:4.12'
148151
androidTestImplementation 'androidx.test:runner:1.2.0'
149152
androidTestImplementation "com.google.truth:truth:$googleTruthVersion"
150-
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
151153
androidTestImplementation 'org.awaitility:awaitility:3.1.0'
152154
androidTestImplementation "io.grpc:grpc-testing:$grpcVersion"
153155
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:2.28.1'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2020 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;
16+
17+
import androidx.test.core.app.ApplicationProvider;
18+
import androidx.test.ext.junit.runners.AndroidJUnit4;
19+
import com.google.firebase.FirebaseApp;
20+
import com.google.firebase.FirebaseOptions.Builder;
21+
import com.google.firebase.testing.integ.StrictModeRule;
22+
import org.junit.Rule;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
26+
@RunWith(AndroidJUnit4.class)
27+
public class StrictModeTest {
28+
29+
@Rule public StrictModeRule strictMode = new StrictModeRule();
30+
31+
@Test
32+
public void initializingFirebaseInAppMessaging_shouldNotViolateStrictMode() {
33+
strictMode.runOnMainThread(
34+
() -> {
35+
FirebaseApp app =
36+
FirebaseApp.initializeApp(
37+
ApplicationProvider.getApplicationContext(),
38+
new Builder()
39+
.setApiKey("api")
40+
.setProjectId("123")
41+
.setApplicationId("appId")
42+
.build(),
43+
"hello");
44+
app.get(FirebaseInAppMessaging.class);
45+
});
46+
}
47+
}

0 commit comments

Comments
 (0)