diff --git a/firebase-storage/CHANGELOG.md b/firebase-storage/CHANGELOG.md index d44617bce67..7594329d4a1 100644 --- a/firebase-storage/CHANGELOG.md +++ b/firebase-storage/CHANGELOG.md @@ -1,4 +1,5 @@ # Unreleased +* [fixed] Fixed an issue where tests were depending on a deprecated feature of the test framework (#6927) # 21.0.1 * [fixed] Fixed an issue where `maxUploadRetryTimeMillis` parameter is ignored when uploading using 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..f47566058a7 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,14 +42,13 @@ 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; /** Tests for {@link FirebaseStorage}. */ @SuppressWarnings("ConstantConditions") @RunWith(RobolectricTestRunner.class) -@Config(sdk = Build.VERSION_CODES.LOLLIPOP_MR1) +@Config(sdk = Build.VERSION_CODES.M) public class DownloadTest { @Rule public RetryRule retryRule = new RetryRule(3); @@ -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;