diff --git a/firebase-inappmessaging/src/test/java/com/google/firebase/inappmessaging/internal/ForegroundNotifierTest.java b/firebase-inappmessaging/src/test/java/com/google/firebase/inappmessaging/internal/ForegroundNotifierTest.java index 2cedc0b7953..af01be33fb6 100644 --- a/firebase-inappmessaging/src/test/java/com/google/firebase/inappmessaging/internal/ForegroundNotifierTest.java +++ b/firebase-inappmessaging/src/test/java/com/google/firebase/inappmessaging/internal/ForegroundNotifierTest.java @@ -16,13 +16,14 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.firebase.inappmessaging.internal.InAppMessageStreamManager.ON_FOREGROUND; +import static org.robolectric.Shadows.shadowOf; +import android.os.Looper; import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.subscribers.TestSubscriber; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @@ -61,7 +62,7 @@ public void notifier_onActivityResumedAfterRunnableExecution_notifiesListener() foregroundNotifier.onActivityResumed(null); // 1 assertThat(subscriber.getEvents().get(0)).hasSize(1); foregroundNotifier.onActivityPaused(null); - Robolectric.flushForegroundThreadScheduler(); + shadowOf(Looper.getMainLooper()).runToEndOfTasks(); foregroundNotifier.onActivityResumed(null); // 2 assertThat(subscriber.getEvents().get(0)).hasSize(2); } diff --git a/firebase-storage/src/test/java/com/google/firebase/storage/DownloadTest.java b/firebase-storage/src/test/java/com/google/firebase/storage/DownloadTest.java index 8f47147ef90..62b2a464eb7 100644 --- a/firebase-storage/src/test/java/com/google/firebase/storage/DownloadTest.java +++ b/firebase-storage/src/test/java/com/google/firebase/storage/DownloadTest.java @@ -18,9 +18,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.robolectric.Shadows.shadowOf; import android.net.Uri; import android.os.Build; +import android.os.Looper; import com.google.android.gms.tasks.Task; import com.google.firebase.FirebaseApp; import com.google.firebase.storage.TestDownloadHelper.StreamDownloadResponse; @@ -40,7 +42,6 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; -import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @@ -137,7 +138,7 @@ public void streamDownloadStateVerification() throws Exception { ControllableSchedulerHelper.getInstance().resume(); for (int i = 0; i < 3000; i++) { - Robolectric.flushForegroundThreadScheduler(); + shadowOf(Looper.getMainLooper()).runToEndOfTasks(); if (semaphore.tryAcquire(2, 1, TimeUnit.MILLISECONDS)) { Assert.assertEquals(bytesDownloaded.get(), bytesTransferred.get()); return; @@ -256,7 +257,7 @@ public void byteDownload() throws Exception { TestDownloadHelper.byteDownload( new StringBuilder(), bitmap -> assertEquals(1076408, bitmap.length)); for (int i = 0; i < 3000; i++) { - Robolectric.flushForegroundThreadScheduler(); + shadowOf(Looper.getMainLooper()).runToEndOfTasks(); if (semaphore.tryAcquire(1, 1, TimeUnit.MILLISECONDS)) { // success! factory.verifyOldMock(); diff --git a/firebase-storage/src/test/java/com/google/firebase/storage/TestUtil.java b/firebase-storage/src/test/java/com/google/firebase/storage/TestUtil.java index 1b70a9d26c6..d2bc5a0ba87 100644 --- a/firebase-storage/src/test/java/com/google/firebase/storage/TestUtil.java +++ b/firebase-storage/src/test/java/com/google/firebase/storage/TestUtil.java @@ -14,6 +14,9 @@ package com.google.firebase.storage; +import static org.robolectric.Shadows.shadowOf; + +import android.os.Looper; import androidx.annotation.Nullable; import androidx.test.core.app.ApplicationProvider; import com.google.android.gms.tasks.Task; @@ -26,7 +29,6 @@ import java.io.StringReader; import java.util.concurrent.TimeUnit; import org.junit.Assert; -import org.robolectric.Robolectric; /** Test helpers. */ public class TestUtil { @@ -138,7 +140,7 @@ static void await(Task task, int timeout, TimeUnit timeUnit) throws Interrupt long timeoutMillis = timeUnit.toMillis(timeout); for (int i = 0; i < timeoutMillis; i++) { - Robolectric.flushForegroundThreadScheduler(); + shadowOf(Looper.getMainLooper()).runToEndOfTasks(); if (task.isComplete()) { // success! return;