public void stop() { if (this.context.isStarted()) { this.context.stop(); } }
@Override public void run() { for (DownloadTask task : scheduleTaskList) { if (!isStarted()) { callbackQueueEndOnSerialLoop(task.isAutoCallbackToUIThread()); break; } task.execute(targetListener); } } });
.setText(holder.priorityTv.getContext().getString(R.string.priority, priority)); holder.prioritySb.setProgress(priority); if (this.context.isStarted()) { holder.prioritySb.setEnabled(false); } else {
doNothing().when(tasks[1]).execute(any(DownloadListener.class)); when(context.isStarted()).thenReturn(true, false); context.start(listener, true); verify(context).executeOnSerialExecutor(any(Runnable.class));
doNothing().when(tasks[0]).execute(any(DownloadListener.class)); doNothing().when(tasks[1]).execute(any(DownloadListener.class)); when(context.isStarted()).thenReturn(false); context.start(listener, true);
@Test public void stop() { context.started = true; context.stop(); assertThat(context.isStarted()).isFalse(); verify(OkDownload.with().downloadDispatcher()).cancel(tasks); }
@Test public void start_withoutQueueListener() throws IOException { mockOkDownload(); // without queue listener final DownloadTask[] tasks = new DownloadTask[2]; tasks[0] = spy(new DownloadTask.Builder("url1", "path", "filename1").build()); tasks[1] = spy(new DownloadTask.Builder("url2", "path", "filename1").build()); context = spy(new DownloadContext(tasks, null, queueSet)); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { final Runnable runnable = invocation.getArgument(0); runnable.run(); return null; } }).when(context).executeOnSerialExecutor(any(Runnable.class)); doNothing().when(tasks[0]).execute(any(DownloadListener.class)); doNothing().when(tasks[1]).execute(any(DownloadListener.class)); assertThat(context.isStarted()).isFalse(); context.start(listener, true); verify(context).executeOnSerialExecutor(any(Runnable.class)); verify(tasks[0]).execute(any(DownloadListener.class)); verify(tasks[1]).execute(any(DownloadListener.class)); assertThat(context.isStarted()).isTrue(); context.start(listener, false); final DownloadDispatcher dispatcher = OkDownload.with().downloadDispatcher(); verify(dispatcher).enqueue(tasks); assertThat(tasks[0].getListener()).isEqualTo(listener); assertThat(tasks[1].getListener()).isEqualTo(listener); }