Skip to content

Commit 0724457

Browse files
committed
Fix test failures with Robolectric 4.9
1. Use legacy LooperMode for tests explicitly, because recent Robolectric releases switch to use PAUSED mode default. Before these tests migrate to PAUSED mode, they use LEGACY mode to pass tests. 2. Migrate Assert.assertThat to Truth.assertThat to avoid using removed APIs. 3. All build.gradle use the same robolectricVersion. 4. Remove unused exclude protobuf-java from Robolectric. 5. Add necessary protobuf-lite dependency on classpath for some ktx modules' tests. Signed-off-by: utzcoz <[email protected]>
1 parent 10cd4ad commit 0724457

File tree

23 files changed

+61
-33
lines changed

23 files changed

+61
-33
lines changed

appcheck/firebase-appcheck-debug/src/test/java/com/google/firebase/appcheck/debug/internal/DebugAppCheckProviderTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
import org.mockito.MockitoAnnotations;
4444
import org.robolectric.RobolectricTestRunner;
4545
import org.robolectric.annotation.Config;
46+
import org.robolectric.annotation.LooperMode;
4647

4748
/** Tests for {@link DebugAppCheckProvider}. */
4849
@RunWith(RobolectricTestRunner.class)
4950
@Config(manifest = Config.NONE)
51+
@LooperMode(LooperMode.Mode.LEGACY)
5052
public class DebugAppCheckProviderTest {
5153

5254
private static final String DEBUG_SECRET = "debugSecret";

appcheck/firebase-appcheck-playintegrity/src/test/java/com/google/firebase/appcheck/playintegrity/internal/PlayIntegrityAppCheckProviderTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@
4747
import org.mockito.MockitoAnnotations;
4848
import org.robolectric.RobolectricTestRunner;
4949
import org.robolectric.annotation.Config;
50+
import org.robolectric.annotation.LooperMode;
5051

5152
/** Tests for {@link PlayIntegrityAppCheckProvider}. */
5253
@RunWith(RobolectricTestRunner.class)
5354
@Config(manifest = Config.NONE)
55+
@LooperMode(LooperMode.Mode.LEGACY)
5456
public class PlayIntegrityAppCheckProviderTest {
5557

5658
private static final String PROJECT_NUMBER = "123456";

appcheck/firebase-appcheck-safetynet/src/test/java/com/google/firebase/appcheck/safetynet/internal/SafetyNetAppCheckProviderTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646
import org.mockito.MockitoAnnotations;
4747
import org.robolectric.RobolectricTestRunner;
4848
import org.robolectric.annotation.Config;
49+
import org.robolectric.annotation.LooperMode;
4950

5051
/** Tests for {@link SafetyNetAppCheckProvider}. */
5152
@RunWith(RobolectricTestRunner.class)
5253
@Config(manifest = Config.NONE)
54+
@LooperMode(LooperMode.Mode.LEGACY)
5355
public class SafetyNetAppCheckProviderTest {
5456

5557
private static final String API_KEY = "apiKey";

appcheck/firebase-appcheck/src/test/java/com/google/firebase/appcheck/internal/DefaultFirebaseAppCheckTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
import org.mockito.MockitoAnnotations;
4242
import org.robolectric.RobolectricTestRunner;
4343
import org.robolectric.annotation.Config;
44+
import org.robolectric.annotation.LooperMode;
4445

4546
/** Tests for {@link DefaultFirebaseAppCheck}. */
4647
@RunWith(RobolectricTestRunner.class)
4748
@Config(manifest = Config.NONE)
49+
@LooperMode(LooperMode.Mode.LEGACY)
4850
public class DefaultFirebaseAppCheckTest {
4951

5052
private static final String EXCEPTION_TEXT = "exceptionText";

appcheck/firebase-appcheck/src/test/java/com/google/firebase/appcheck/internal/DefaultTokenRefresherTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import org.mockito.Mock;
3434
import org.mockito.MockitoAnnotations;
3535
import org.robolectric.RobolectricTestRunner;
36+
import org.robolectric.annotation.LooperMode;
3637

3738
@RunWith(RobolectricTestRunner.class)
39+
@LooperMode(LooperMode.Mode.LEGACY)
3840
public class DefaultTokenRefresherTest {
3941

4042
private static final long TIME_TO_REFRESH_MILLIS = 1000L;

firebase-appdistribution-api/src/test/java/com/google/firebase/appdistribution/internal/FirebaseAppDistributionProxyTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import org.junit.runner.RunWith;
3434
import org.robolectric.Robolectric;
3535
import org.robolectric.RobolectricTestRunner;
36+
import org.robolectric.annotation.LooperMode;
3637

3738
@RunWith(RobolectricTestRunner.class)
39+
@LooperMode(LooperMode.Mode.LEGACY)
3840
public class FirebaseAppDistributionProxyTest {
3941

4042
private FirebaseAppDistribution firebaseAppDistribution;

firebase-appdistribution/firebase-appdistribution.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies {
5151
runtimeOnly project(':firebase-installations')
5252

5353
testImplementation 'junit:junit:4.13.2'
54-
testImplementation "org.robolectric:robolectric:4.9"
54+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
5555
testImplementation "com.google.truth:truth:$googleTruthVersion"
5656
testImplementation 'org.mockito:mockito-inline:3.4.0'
5757
androidTestImplementation "org.mockito:mockito-android:3.4.0"

firebase-common/data-collection-tests/src/test/java/com/google/firebase/DataCollectionPostNDefaultDisabledTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
import org.junit.Test;
2828
import org.junit.runner.RunWith;
2929
import org.robolectric.annotation.Config;
30+
import org.robolectric.annotation.LooperMode;
3031

3132
@RunWith(AndroidJUnit4.class)
3233
@Config(sdk = 25)
34+
@LooperMode(LooperMode.Mode.LEGACY)
3335
public class DataCollectionPostNDefaultDisabledTest {
3436

3537
@Test

firebase-common/data-collection-tests/src/test/java/com/google/firebase/DataCollectionPreNDefaultDisabledTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.Test;
2626
import org.junit.runner.RunWith;
2727
import org.robolectric.annotation.Config;
28+
import org.robolectric.annotation.LooperMode;
2829

2930
@RunWith(AndroidJUnit4.class)
3031
@Config(sdk = 19)
@@ -81,6 +82,7 @@ public void setDataCollectionDefaultEnabledTrue_shouldUpdateSharedPrefs() {
8182
}
8283

8384
@Test
85+
@LooperMode(LooperMode.Mode.LEGACY)
8486
public void setDataCollectionDefaultEnabledTrue_shouldEmitEvents() {
8587
withApp(
8688
app -> {

firebase-config/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.mockito.MockitoAnnotations;
8383
import org.robolectric.RobolectricTestRunner;
8484
import org.robolectric.annotation.Config;
85+
import org.robolectric.annotation.LooperMode;
8586
import org.skyscreamer.jsonassert.JSONAssert;
8687

8788
/**
@@ -93,6 +94,7 @@
9394
@Config(
9495
manifest = Config.NONE,
9596
shadows = {ShadowPreconditions.class})
97+
@LooperMode(LooperMode.Mode.LEGACY)
9698
public final class FirebaseRemoteConfigTest {
9799
private static final String APP_ID = "1:14368190084:android:09cb977358c6f241";
98100
private static final String API_KEY = "AIzaSyabcdefghijklmnopqrstuvwxyz1234567";

0 commit comments

Comments
 (0)