Commit 3c010775 by eguven Committed by Oliver Woodman

Add STOPPED state to DownloadManager

PiperOrigin-RevId: 226460891
parent 173f3689
...@@ -41,6 +41,7 @@ import org.mockito.MockitoAnnotations; ...@@ -41,6 +41,7 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;
/** Tests {@link DownloadManager}. */ /** Tests {@link DownloadManager}. */
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
...@@ -69,6 +70,7 @@ public class DownloadManagerTest { ...@@ -69,6 +70,7 @@ public class DownloadManagerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
ShadowLog.stream = System.out;
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
uri1 = Uri.parse("http://abc.com/media1"); uri1 = Uri.parse("http://abc.com/media1");
uri2 = Uri.parse("http://abc.com/media2"); uri2 = Uri.parse("http://abc.com/media2");
...@@ -314,6 +316,7 @@ public class DownloadManagerTest { ...@@ -314,6 +316,7 @@ public class DownloadManagerTest {
downloader1.assertStarted(); downloader1.assertStarted();
downloader2.assertDoesNotStart(); downloader2.assertDoesNotStart();
runner2.getTask().assertQueued();
downloader1.unblock(); downloader1.unblock();
downloader2.assertStarted(); downloader2.assertStarted();
downloader2.unblock(); downloader2.unblock();
...@@ -390,11 +393,11 @@ public class DownloadManagerTest { ...@@ -390,11 +393,11 @@ public class DownloadManagerTest {
runOnMainThread(() -> downloadManager.stopDownloads()); runOnMainThread(() -> downloadManager.stopDownloads());
runner1.getTask().assertQueued(); runner1.getTask().assertStopped();
// remove actions aren't stopped. // remove actions aren't stopped.
runner2.getDownloader(0).unblock().assertReleased(); runner2.getDownloader(0).unblock().assertReleased();
runner2.getTask().assertQueued(); runner2.getTask().assertStopped();
// Although remove2 is finished, download2 doesn't start. // Although remove2 is finished, download2 doesn't start.
runner2.getDownloader(1).assertDoesNotStart(); runner2.getDownloader(1).assertDoesNotStart();
...@@ -534,6 +537,10 @@ public class DownloadManagerTest { ...@@ -534,6 +537,10 @@ public class DownloadManagerTest {
return assertState(DownloadState.STATE_QUEUED); return assertState(DownloadState.STATE_QUEUED);
} }
private TaskWrapper assertStopped() {
return assertState(DownloadState.STATE_STOPPED);
}
private TaskWrapper assertState(@State int expectedState) { private TaskWrapper assertState(@State int expectedState) {
while (true) { while (true) {
Integer state = null; Integer state = null;
...@@ -542,6 +549,7 @@ public class DownloadManagerTest { ...@@ -542,6 +549,7 @@ public class DownloadManagerTest {
} catch (InterruptedException e) { } catch (InterruptedException e) {
fail(e.getMessage()); fail(e.getMessage());
} }
assertThat(state).isNotNull();
if (expectedState == state) { if (expectedState == state) {
return this; return this;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment