Skip to content

Commit 2253cd4

Browse files
authored
Bump Robolectric to 4.9 (#4161)
* Add plexus-utils for firebase-database tests Looks like firebase-database tests use plexus-utils dependency of Robolectric directly. But this dependency was removed by Robolectric. So this CL adds plexus-utils explictly for firebase-database tests. Signed-off-by: utzcoz <[email protected]> * Bump Robolectric to 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 except transport-backend-cct because Robolectric 4.8+ has compatibility problem for TelephonyManager with low compile/targetSdkversion. To keep httpclient compatibility, transport-backend-ccts continues to use Robolectric 4.3.1. 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]> Signed-off-by: utzcoz <[email protected]>
1 parent 83969d7 commit 2253cd4

File tree

26 files changed

+66
-37
lines changed

26 files changed

+66
-37
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;

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ext {
5151
supportAnnotationsVersion = '28.0.0'
5252
googleTruthVersion = '1.1.2'
5353
grpcVersion = '1.48.1'
54-
robolectricVersion = '4.3.1'
54+
robolectricVersion = '4.9'
5555
protocVersion = '3.17.3'
5656
javaliteVersion = '3.17.3'
5757
}

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.8.1"
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";

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.mockito.MockitoAnnotations;
4949
import org.robolectric.RobolectricTestRunner;
5050
import org.robolectric.annotation.Config;
51+
import org.robolectric.annotation.LooperMode;
5152

5253
/**
5354
* Unit tests for the Firebase Remote Config Component.
@@ -92,6 +93,7 @@ public void setUp() {
9293
}
9394

9495
@Test
96+
@LooperMode(LooperMode.Mode.LEGACY)
9597
public void frc2p_doesNotCallAbt() throws Exception {
9698

9799
FirebaseRemoteConfig fireperfFrc =
@@ -106,6 +108,7 @@ public void frc2p_doesNotCallAbt() throws Exception {
106108
}
107109

108110
@Test
111+
@LooperMode(LooperMode.Mode.LEGACY)
109112
public void frcNonMainFirebaseApp_doesNotCallAbt() throws Exception {
110113

111114
when(mockFirebaseApp.getName()).thenReturn("secondary");

firebase-config/src/test/java/com/google/firebase/remoteconfig/internal/ConfigFetchHandlerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import org.mockito.MockitoAnnotations;
9191
import org.robolectric.RobolectricTestRunner;
9292
import org.robolectric.annotation.Config;
93+
import org.robolectric.annotation.LooperMode;
9394
import org.skyscreamer.jsonassert.JSONAssert;
9495

9596
/**
@@ -99,6 +100,7 @@
99100
*/
100101
@RunWith(RobolectricTestRunner.class)
101102
@Config(manifest = Config.NONE)
103+
@LooperMode(LooperMode.Mode.LEGACY)
102104
public class ConfigFetchHandlerTest {
103105
private static final String INSTALLATION_ID = "'fL71_VyL3uo9jNMWu1L60S";
104106
private static final String INSTALLATION_AUTH_TOKEN =

firebase-crashlytics/firebase-crashlytics.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ dependencies {
7979

8080
testImplementation 'androidx.test:runner:1.4.0'
8181
testImplementation 'androidx.test:core:1.4.0'
82-
testImplementation "org.robolectric:robolectric:4.5"
82+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
8383
testImplementation 'junit:junit:4.13.2'
8484
testImplementation 'org.mockito:mockito-core:3.4.3'
8585

firebase-database/firebase-database.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ dependencies {
100100

101101
testImplementation 'junit:junit:4.12'
102102
testImplementation 'org.mockito:mockito-core:2.25.0'
103+
testImplementation 'org.codehaus.plexus:plexus-utils:3.4.2'
103104
testImplementation "org.robolectric:robolectric:$robolectricVersion"
104105
testImplementation 'com.firebase:firebase-token-generator:2.0.0'
105106
testImplementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'

firebase-firestore/firebase-firestore.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ dependencies {
150150
testImplementation 'androidx.test:core:1.2.0'
151151
testImplementation "org.hamcrest:hamcrest-junit:2.0.0.0"
152152
testImplementation 'org.mockito:mockito-core:2.25.0'
153-
testImplementation ("org.robolectric:robolectric:4.8.2") {
154-
exclude group: 'com.google.protobuf', module: 'protobuf-java'
155-
}
153+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
156154
testImplementation "com.google.truth:truth:$googleTruthVersion"
157155
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
158156
testImplementation 'com.google.guava:guava-testlib:12.0-rc2'

firebase-firestore/ktx/ktx.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ dependencies {
5959
implementation 'androidx.annotation:annotation:1.1.0'
6060
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
6161
implementation 'com.google.android.gms:play-services-basement:18.1.0'
62+
testCompileOnly "com.google.protobuf:protobuf-java:$protocVersion"
6263
testImplementation project(':firebase-database-collection')
6364
testImplementation 'org.mockito:mockito-core:2.25.0'
6465
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'

firebase-inappmessaging-display/src/test/java/com/google/firebase/inappmessaging/display/FirebaseInAppMessagingDisplayTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@
8787
import org.robolectric.Robolectric;
8888
import org.robolectric.RobolectricTestRunner;
8989
import org.robolectric.annotation.Config;
90+
import org.robolectric.annotation.LooperMode;
9091
import org.robolectric.shadows.ShadowActivity;
9192
import org.robolectric.shadows.ShadowPackageManager;
9293

9394
@RunWith(RobolectricTestRunner.class)
9495
@Config(sdk = 21, qualifiers = "port")
96+
@LooperMode(LooperMode.Mode.LEGACY)
9597
public class FirebaseInAppMessagingDisplayTest {
9698

9799
private com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay fiamUI;

firebase-inappmessaging/src/test/java/com/google/firebase/inappmessaging/internal/InAppMessageStreamManagerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@
7171
import org.mockito.MockitoAnnotations;
7272
import org.robolectric.RobolectricTestRunner;
7373
import org.robolectric.annotation.Config;
74+
import org.robolectric.annotation.LooperMode;
7475

7576
// TODO: Refactor and clean this logic
7677
@RunWith(RobolectricTestRunner.class)
7778
@Config(manifest = Config.NONE)
79+
@LooperMode(LooperMode.Mode.LEGACY)
7880
public class InAppMessageStreamManagerTest {
7981
private static final long PAST = 1000000;
8082
private static final long NOW = PAST + 100000;

firebase-inappmessaging/src/test/java/com/google/firebase/inappmessaging/internal/MetricsLoggerClientTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@
5555
import org.mockito.MockitoAnnotations;
5656
import org.robolectric.RobolectricTestRunner;
5757
import org.robolectric.annotation.Config;
58+
import org.robolectric.annotation.LooperMode;
5859

5960
@RunWith(RobolectricTestRunner.class)
6061
@Config(manifest = Config.NONE)
62+
@LooperMode(LooperMode.Mode.LEGACY)
6163
public class MetricsLoggerClientTest {
6264
private static final long PAST = 1000000;
6365
private static final long NOW = PAST + 100000;

0 commit comments

Comments
 (0)