method2testcases
stringlengths 118
3.08k
|
---|
### Question:
DownloadListener2 implements DownloadListener { @Override public void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode, @NonNull Map<String, List<String>> responseHeaderFields) { } @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); }### Answer:
@Test public void connectEnd() throws Exception { listener2.connectEnd(task, 1, 200, headerFields); }
|
### Question:
StatusUtil { public static boolean isCompleted(@NonNull DownloadTask task) { return isCompletedOrUnknown(task) == Status.COMPLETED; } static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task); static Status getStatus(@NonNull DownloadTask task); static Status getStatus(@NonNull String url, @NonNull String parentPath,
@Nullable String filename); static boolean isCompleted(@NonNull DownloadTask task); static Status isCompletedOrUnknown(@NonNull DownloadTask task); static boolean isCompleted(@NonNull String url, @NonNull String parentPath,
@Nullable String filename); @Nullable static BreakpointInfo getCurrentInfo(@NonNull String url,
@NonNull String parentPath,
@Nullable String filename); @Nullable static BreakpointInfo getCurrentInfo(@NonNull DownloadTask task); }### Answer:
@Test public void isCompleted() throws IOException { assertThat(file.exists()).isFalse(); boolean isCompleted = StatusUtil .isCompleted(url, file.getParentFile().getPath(), file.getName()); assertThat(isCompleted).isFalse(); file.getParentFile().mkdirs(); file.createNewFile(); isCompleted = StatusUtil .isCompleted(url, file.getParentFile().getPath(), file.getName()); assertThat(isCompleted).isTrue(); final BreakpointStore store = OkDownload.with().breakpointStore(); doReturn(mock(BreakpointInfo.class)).when(store).get(anyInt()); isCompleted = StatusUtil .isCompleted(url, file.getParentFile().getPath(), file.getName()); assertThat(isCompleted).isFalse(); }
|
### Question:
DownloadListener2 implements DownloadListener { @Override public void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength) { } @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); }### Answer:
@Test public void fetchStart() throws Exception { listener2.fetchStart(task, 1, 2); }
|
### Question:
DownloadListener2 implements DownloadListener { @Override public void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes) { } @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); }### Answer:
@Test public void fetchProgress() throws Exception { listener2.fetchProgress(task, 1, 2); }
|
### Question:
DownloadListener2 implements DownloadListener { @Override public void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength) { } @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); }### Answer:
@Test public void fetchEnd() throws Exception { listener2.fetchEnd(task, 1, 2); }
|
### Question:
DownloadListener1 implements DownloadListener,
Listener1Assist.Listener1Callback, ListenerAssist { @Override public final void taskStart(@NonNull DownloadTask task) { assist.taskStart(task); } DownloadListener1(Listener1Assist assist); DownloadListener1(); @Override boolean isAlwaysRecoverAssistModel(); @Override void setAlwaysRecoverAssistModel(boolean isAlwaysRecoverAssistModel); @Override void setAlwaysRecoverAssistModelIfNotSet(boolean isAlwaysRecoverAssistModel); @Override final void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override final void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); }### Answer:
@Test public void taskStart() { listener1.taskStart(task); verify(listener1.assist).taskStart(eq(task)); }
|
### Question:
DownloadListener1 implements DownloadListener,
Listener1Assist.Listener1Callback, ListenerAssist { @Override public void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull ResumeFailedCause cause) { assist.downloadFromBeginning(task, info, cause); } DownloadListener1(Listener1Assist assist); DownloadListener1(); @Override boolean isAlwaysRecoverAssistModel(); @Override void setAlwaysRecoverAssistModel(boolean isAlwaysRecoverAssistModel); @Override void setAlwaysRecoverAssistModelIfNotSet(boolean isAlwaysRecoverAssistModel); @Override final void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override final void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); }### Answer:
@Test public void downloadFromBeginning() { final ResumeFailedCause cause = mock(ResumeFailedCause.class); listener1.downloadFromBeginning(task, info, cause); verify(listener1.assist).downloadFromBeginning(eq(task), eq(info), eq(cause)); }
|
### Question:
DownloadListener1 implements DownloadListener,
Listener1Assist.Listener1Callback, ListenerAssist { @Override public void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info) { assist.downloadFromBreakpoint(task, info); } DownloadListener1(Listener1Assist assist); DownloadListener1(); @Override boolean isAlwaysRecoverAssistModel(); @Override void setAlwaysRecoverAssistModel(boolean isAlwaysRecoverAssistModel); @Override void setAlwaysRecoverAssistModelIfNotSet(boolean isAlwaysRecoverAssistModel); @Override final void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override final void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); }### Answer:
@Test public void downloadFromBreakpoint() { listener1.downloadFromBreakpoint(task, info); verify(listener1.assist).downloadFromBreakpoint(eq(task), eq(info)); }
|
### Question:
DownloadListener1 implements DownloadListener,
Listener1Assist.Listener1Callback, ListenerAssist { @Override public void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode, @NonNull Map<String, List<String>> responseHeaderFields) { assist.connectEnd(task); } DownloadListener1(Listener1Assist assist); DownloadListener1(); @Override boolean isAlwaysRecoverAssistModel(); @Override void setAlwaysRecoverAssistModel(boolean isAlwaysRecoverAssistModel); @Override void setAlwaysRecoverAssistModelIfNotSet(boolean isAlwaysRecoverAssistModel); @Override final void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override final void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); }### Answer:
@Test public void connectEnd() { listener1.connectEnd(task, 1, 200, tmpFields); verify(listener1.assist).connectEnd(eq(task)); }
|
### Question:
DownloadListener1 implements DownloadListener,
Listener1Assist.Listener1Callback, ListenerAssist { @Override public void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes) { assist.fetchProgress(task, increaseBytes); } DownloadListener1(Listener1Assist assist); DownloadListener1(); @Override boolean isAlwaysRecoverAssistModel(); @Override void setAlwaysRecoverAssistModel(boolean isAlwaysRecoverAssistModel); @Override void setAlwaysRecoverAssistModelIfNotSet(boolean isAlwaysRecoverAssistModel); @Override final void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override final void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); }### Answer:
@Test public void fetchProgress() { listener1.fetchProgress(task, 1, 2); verify(listener1.assist).fetchProgress(eq(task), eq(2L)); }
|
### Question:
DownloadListener1 implements DownloadListener,
Listener1Assist.Listener1Callback, ListenerAssist { @Override public boolean isAlwaysRecoverAssistModel() { return assist.isAlwaysRecoverAssistModel(); } DownloadListener1(Listener1Assist assist); DownloadListener1(); @Override boolean isAlwaysRecoverAssistModel(); @Override void setAlwaysRecoverAssistModel(boolean isAlwaysRecoverAssistModel); @Override void setAlwaysRecoverAssistModelIfNotSet(boolean isAlwaysRecoverAssistModel); @Override final void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override final void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); }### Answer:
@Test public void isAlwaysRecoverAssistModel() { when(assist.isAlwaysRecoverAssistModel()).thenReturn(true); assertThat(listener1.isAlwaysRecoverAssistModel()).isTrue(); when(assist.isAlwaysRecoverAssistModel()).thenReturn(false); assertThat(listener1.isAlwaysRecoverAssistModel()).isFalse(); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void taskStart(@NonNull DownloadTask task) { for (DownloadListener listener : listenerList) { listener.taskStart(task); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void taskStart() throws Exception { listenerBunch.taskStart(task); verify(listener1).taskStart(eq(task)); verify(listener2).taskStart(eq(task)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void connectTrialStart(@NonNull DownloadTask task, @NonNull Map<String, List<String>> requestHeaderFields) { for (DownloadListener listener : listenerList) { listener.connectTrialStart(task, requestHeaderFields); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void connectTrialStart() throws Exception { listenerBunch.connectTrialStart(task, headerFields); verify(listener1).connectTrialStart(eq(task), eq(headerFields)); verify(listener2).connectTrialStart(eq(task), eq(headerFields)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void connectTrialEnd(@NonNull DownloadTask task, int responseCode, @NonNull Map<String, List<String>> responseHeaderFields) { for (DownloadListener listener : listenerList) { listener.connectTrialEnd(task, responseCode, responseHeaderFields); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void connectTrialEnd() throws Exception { listenerBunch.connectTrialEnd(task, 200, headerFields); verify(listener1).connectTrialEnd(eq(task), eq(200), eq(headerFields)); verify(listener2).connectTrialEnd(eq(task), eq(200), eq(headerFields)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull ResumeFailedCause cause) { for (DownloadListener listener : listenerList) { listener.downloadFromBeginning(task, info, cause); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void downloadFromBeginning() throws Exception { listenerBunch.downloadFromBeginning(task, info, resumeFailedCause); verify(listener1).downloadFromBeginning(eq(task), eq(info), eq(resumeFailedCause)); verify(listener2).downloadFromBeginning(eq(task), eq(info), eq(resumeFailedCause)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info) { for (DownloadListener listener : listenerList) { listener.downloadFromBreakpoint(task, info); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void downloadFromBreakpoint() throws Exception { listenerBunch.downloadFromBreakpoint(task, info); verify(listener1).downloadFromBreakpoint(eq(task), eq(info)); verify(listener2).downloadFromBreakpoint(eq(task), eq(info)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void connectStart(@NonNull DownloadTask task, int blockIndex, @NonNull Map<String, List<String>> requestHeaderFields) { for (DownloadListener listener : listenerList) { listener.connectStart(task, blockIndex, requestHeaderFields); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void connectStart() throws Exception { listenerBunch.connectStart(task, 1, headerFields); verify(listener1).connectStart(eq(task), eq(1), eq(headerFields)); verify(listener2).connectStart(eq(task), eq(1), eq(headerFields)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode, @NonNull Map<String, List<String>> responseHeaderFields) { for (DownloadListener listener : listenerList) { listener.connectEnd(task, blockIndex, responseCode, responseHeaderFields); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void connectEnd() throws Exception { listenerBunch.connectEnd(task, 1, 1, headerFields); verify(listener1).connectEnd(eq(task), eq(1), eq(1), eq(headerFields)); verify(listener2).connectEnd(eq(task), eq(1), eq(1), eq(headerFields)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength) { for (DownloadListener listener : listenerList) { listener.fetchStart(task, blockIndex, contentLength); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void fetchStart() throws Exception { listenerBunch.fetchStart(task, 1, 1L); verify(listener1).fetchStart(eq(task), eq(1), eq(1L)); verify(listener2).fetchStart(eq(task), eq(1), eq(1L)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes) { for (DownloadListener listener : listenerList) { listener.fetchProgress(task, blockIndex, increaseBytes); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void fetchProgress() throws Exception { listenerBunch.fetchProgress(task, 1, 1L); verify(listener1).fetchProgress(eq(task), eq(1), eq(1L)); verify(listener2).fetchProgress(eq(task), eq(1), eq(1L)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength) { for (DownloadListener listener : listenerList) { listener.fetchEnd(task, blockIndex, contentLength); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void fetchEnd() throws Exception { listenerBunch.fetchEnd(task, 1, 1L); verify(listener1).fetchEnd(eq(task), eq(1), eq(1L)); verify(listener2).fetchEnd(eq(task), eq(1), eq(1L)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { @Override public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause) { for (DownloadListener listener : listenerList) { listener.taskEnd(task, cause, realCause); } } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void taskEnd() { listenerBunch.taskEnd(task, endCause, realCause); verify(listener1).taskEnd(eq(task), eq(endCause), eq(realCause)); verify(listener2).taskEnd(eq(task), eq(endCause), eq(realCause)); }
|
### Question:
DownloadListenerBunch implements DownloadListener { public boolean contain(DownloadListener targetListener) { for (DownloadListener listener : listenerList) { if (listener == targetListener) return true; } return false; } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void contain() throws Exception { assertThat(listenerBunch.contain(listener1)).isTrue(); assertThat(listenerBunch.contain(listener2)).isTrue(); assertThat(listenerBunch.contain(mock(DownloadListener.class))).isFalse(); }
|
### Question:
DownloadListenerBunch implements DownloadListener { public int indexOf(DownloadListener targetListener) { for (int index = 0; index < listenerList.length; index++) { final DownloadListener listener = listenerList[index]; if (listener == targetListener) return index; } return -1; } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void taskStart(@NonNull DownloadTask task); @Override void connectTrialStart(@NonNull DownloadTask task,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectTrialEnd(@NonNull DownloadTask task, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull ResumeFailedCause cause); @Override void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info); @Override void connectStart(@NonNull DownloadTask task, int blockIndex,
@NonNull Map<String, List<String>> requestHeaderFields); @Override void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode,
@NonNull Map<String, List<String>> responseHeaderFields); @Override void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes); @Override void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength); @Override void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); boolean contain(DownloadListener targetListener); int indexOf(DownloadListener targetListener); }### Answer:
@Test public void indexOf() { assertThat(listenerBunch.indexOf(listener1)).isZero(); assertThat(listenerBunch.indexOf(listener2)).isOne(); assertThat(listenerBunch.indexOf(mock(DownloadListener.class))).isEqualTo(-1); }
|
### Question:
DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { @Override protected void finished() { OkDownload.with().downloadDispatcher().finish(this); Util.d(TAG, "call is finished " + task.getId()); } private DownloadCall(DownloadTask task, boolean asyncExecuted, @NonNull DownloadStore store); DownloadCall(DownloadTask task, boolean asyncExecuted,
@NonNull ArrayList<DownloadChain> runningBlockList,
@NonNull DownloadStore store); static DownloadCall create(DownloadTask task, boolean asyncExecuted,
@NonNull DownloadStore store); boolean cancel(); boolean isCanceled(); boolean isFinishing(); @Override void execute(); boolean equalsTask(@NonNull DownloadTask task); @Nullable File getFile(); @SuppressFBWarnings(value = "Eq", justification = "This special case is just for task priority") @Override int compareTo(@NonNull DownloadCall o); final DownloadTask task; final boolean asyncExecuted; }### Answer:
@Test public void finished_callToDispatch() { call.finished(); verify(OkDownload.with().downloadDispatcher()).finish(call); }
|
### Question:
DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { @SuppressFBWarnings(value = "Eq", justification = "This special case is just for task priority") @Override public int compareTo(@NonNull DownloadCall o) { return o.getPriority() - getPriority(); } private DownloadCall(DownloadTask task, boolean asyncExecuted, @NonNull DownloadStore store); DownloadCall(DownloadTask task, boolean asyncExecuted,
@NonNull ArrayList<DownloadChain> runningBlockList,
@NonNull DownloadStore store); static DownloadCall create(DownloadTask task, boolean asyncExecuted,
@NonNull DownloadStore store); boolean cancel(); boolean isCanceled(); boolean isFinishing(); @Override void execute(); boolean equalsTask(@NonNull DownloadTask task); @Nullable File getFile(); @SuppressFBWarnings(value = "Eq", justification = "This special case is just for task priority") @Override int compareTo(@NonNull DownloadCall o); final DownloadTask task; final boolean asyncExecuted; }### Answer:
@Test public void compareTo() { final DownloadCall compareCall = mock(DownloadCall.class); when(compareCall.getPriority()).thenReturn(6); when(call.getPriority()).thenReturn(3); final int result = call.compareTo(compareCall); assertThat(result).isEqualTo(3); }
|
### Question:
DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { void startBlocks(List<DownloadChain> tasks) throws InterruptedException { ArrayList<Future> futures = new ArrayList<>(tasks.size()); try { for (DownloadChain chain : tasks) { futures.add(submitChain(chain)); } blockChainList.addAll(tasks); for (Future future : futures) { if (!future.isDone()) { try { future.get(); } catch (CancellationException | ExecutionException ignore) { } } } } catch (Throwable t) { for (Future future : futures) { future.cancel(true); } throw t; } finally { blockChainList.removeAll(tasks); } } private DownloadCall(DownloadTask task, boolean asyncExecuted, @NonNull DownloadStore store); DownloadCall(DownloadTask task, boolean asyncExecuted,
@NonNull ArrayList<DownloadChain> runningBlockList,
@NonNull DownloadStore store); static DownloadCall create(DownloadTask task, boolean asyncExecuted,
@NonNull DownloadStore store); boolean cancel(); boolean isCanceled(); boolean isFinishing(); @Override void execute(); boolean equalsTask(@NonNull DownloadTask task); @Nullable File getFile(); @SuppressFBWarnings(value = "Eq", justification = "This special case is just for task priority") @Override int compareTo(@NonNull DownloadCall o); final DownloadTask task; final boolean asyncExecuted; }### Answer:
@Test public void startBlocks() throws InterruptedException { ArrayList<DownloadChain> runningBlockList = spy(new ArrayList<DownloadChain>()); call = spy(new DownloadCall(task, false, runningBlockList, store)); final Future mockFuture = mock(Future.class); doReturn(mockFuture).when(call).submitChain(any(DownloadChain.class)); List<DownloadChain> chains = new ArrayList<>(); chains.add(mock(DownloadChain.class)); chains.add(mock(DownloadChain.class)); chains.add(mock(DownloadChain.class)); call.startBlocks(chains); verify(call, times(3)).submitChain(any(DownloadChain.class)); verify(runningBlockList).addAll(eq(chains)); verify(runningBlockList).removeAll(eq(chains)); }
|
### Question:
StatusUtil { @Nullable public static BreakpointInfo getCurrentInfo(@NonNull String url, @NonNull String parentPath, @Nullable String filename) { return getCurrentInfo(createFinder(url, parentPath, filename)); } static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task); static Status getStatus(@NonNull DownloadTask task); static Status getStatus(@NonNull String url, @NonNull String parentPath,
@Nullable String filename); static boolean isCompleted(@NonNull DownloadTask task); static Status isCompletedOrUnknown(@NonNull DownloadTask task); static boolean isCompleted(@NonNull String url, @NonNull String parentPath,
@Nullable String filename); @Nullable static BreakpointInfo getCurrentInfo(@NonNull String url,
@NonNull String parentPath,
@Nullable String filename); @Nullable static BreakpointInfo getCurrentInfo(@NonNull DownloadTask task); }### Answer:
@Test public void getCurrentInfo() { final BreakpointStore store = OkDownload.with().breakpointStore(); final BreakpointInfo origin = mock(BreakpointInfo.class); doReturn(origin).when(store).get(anyInt()); StatusUtil.getCurrentInfo(mock(DownloadTask.class)); verify(origin).copy(); }
@Test public void getCurrentInfo_urlParentPathFilename() { final BreakpointStore store = OkDownload.with().breakpointStore(); final BreakpointInfo origin = mock(BreakpointInfo.class); doReturn(origin).when(store).get(anyInt()); StatusUtil.getCurrentInfo("https: verify(origin).copy(); }
|
### Question:
DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { void assembleBlockAndCallbackFromBeginning(@NonNull BreakpointInfo info, @NonNull BreakpointRemoteCheck remoteCheck, @NonNull ResumeFailedCause failedCause) { Util.assembleBlock(task, info, remoteCheck.getInstanceLength(), remoteCheck.isAcceptRange()); OkDownload.with().callbackDispatcher().dispatch() .downloadFromBeginning(task, info, failedCause); } private DownloadCall(DownloadTask task, boolean asyncExecuted, @NonNull DownloadStore store); DownloadCall(DownloadTask task, boolean asyncExecuted,
@NonNull ArrayList<DownloadChain> runningBlockList,
@NonNull DownloadStore store); static DownloadCall create(DownloadTask task, boolean asyncExecuted,
@NonNull DownloadStore store); boolean cancel(); boolean isCanceled(); boolean isFinishing(); @Override void execute(); boolean equalsTask(@NonNull DownloadTask task); @Nullable File getFile(); @SuppressFBWarnings(value = "Eq", justification = "This special case is just for task priority") @Override int compareTo(@NonNull DownloadCall o); final DownloadTask task; final boolean asyncExecuted; }### Answer:
@Test public void assembleBlockAndCallbackFromBeginning() { final BreakpointRemoteCheck remoteCheck = mock(BreakpointRemoteCheck.class); final ResumeFailedCause failedCause = mock(ResumeFailedCause.class); call.assembleBlockAndCallbackFromBeginning(info, remoteCheck, failedCause); final DownloadListener listener = OkDownload.with().callbackDispatcher().dispatch(); verify(listener).downloadFromBeginning(eq(task), eq(info), eq(failedCause)); }
|
### Question:
DownloadChain implements Runnable { public DownloadConnection.Connected processConnect() throws IOException { if (cache.isInterrupt()) throw InterruptException.SIGNAL; return connectInterceptorList.get(connectIndex++).interceptConnect(this); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void processConnect() throws IOException { final Interceptor.Connect connect = mock(Interceptor.Connect.class); chain.connectInterceptorList.add(connect); chain.connectIndex = 0; chain.processConnect(); assertThat(chain.connectIndex).isEqualTo(1); verify(connect).interceptConnect(chain); }
|
### Question:
DownloadChain implements Runnable { public long processFetch() throws IOException { if (cache.isInterrupt()) throw InterruptException.SIGNAL; return fetchInterceptorList.get(fetchIndex++).interceptFetch(this); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void processFetch() throws IOException { final Interceptor.Fetch fetch = mock(Interceptor.Fetch.class); chain.fetchInterceptorList.add(fetch); chain.fetchIndex = 0; chain.processFetch(); assertThat(chain.fetchIndex).isEqualTo(1); verify(fetch).interceptFetch(chain); }
|
### Question:
DownloadChain implements Runnable { public long loopFetch() throws IOException { if (fetchIndex == fetchInterceptorList.size()) { fetchIndex--; } return processFetch(); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void loopFetch() throws IOException { final Interceptor.Fetch fetch1 = mock(Interceptor.Fetch.class); chain.fetchInterceptorList.add(fetch1); final Interceptor.Fetch fetch2 = mock(Interceptor.Fetch.class); chain.fetchInterceptorList.add(fetch2); final Interceptor.Fetch fetch3 = mock(Interceptor.Fetch.class); chain.fetchInterceptorList.add(fetch3); chain.fetchIndex = 0; chain.loopFetch(); chain.loopFetch(); chain.loopFetch(); chain.loopFetch(); chain.loopFetch(); assertThat(chain.fetchIndex).isEqualTo(3); verify(fetch1).interceptFetch(chain); verify(fetch2).interceptFetch(chain); verify(fetch3, times(3)).interceptFetch(chain); }
|
### Question:
DownloadChain implements Runnable { public void flushNoCallbackIncreaseBytes() { if (noCallbackIncreaseBytes == 0) return; callbackDispatcher.dispatch().fetchProgress(task, blockIndex, noCallbackIncreaseBytes); noCallbackIncreaseBytes = 0; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void flushNoCallbackIncreaseBytes() { chain.increaseCallbackBytes(10L); chain.increaseCallbackBytes(6L); assertThat(chain.noCallbackIncreaseBytes).isEqualTo(16L); chain.flushNoCallbackIncreaseBytes(); verify(OkDownload.with().callbackDispatcher().dispatch()) .fetchProgress(eq(chain.getTask()), eq(0), eq(16L)); assertThat(chain.noCallbackIncreaseBytes).isZero(); }
|
### Question:
StatusUtil { @NonNull static DownloadTask createFinder(@NonNull String url, @NonNull String parentPath, @Nullable String filename) { return new DownloadTask.Builder(url, parentPath, filename) .build(); } static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task); static Status getStatus(@NonNull DownloadTask task); static Status getStatus(@NonNull String url, @NonNull String parentPath,
@Nullable String filename); static boolean isCompleted(@NonNull DownloadTask task); static Status isCompletedOrUnknown(@NonNull DownloadTask task); static boolean isCompleted(@NonNull String url, @NonNull String parentPath,
@Nullable String filename); @Nullable static BreakpointInfo getCurrentInfo(@NonNull String url,
@NonNull String parentPath,
@Nullable String filename); @Nullable static BreakpointInfo getCurrentInfo(@NonNull DownloadTask task); }### Answer:
@Test public void createFinder() { DownloadTask task = StatusUtil.createFinder(url, file.getParent(), null); assertThat(task.getFile()).isNull(); assertFile(task.getParentFile()).isEqualTo(file.getParentFile()); task = StatusUtil.createFinder(url, file.getParent(), file.getName()); assertFile(task.getFile()).isEqualTo(file); }
|
### Question:
DownloadChain implements Runnable { public void setResponseContentLength(long responseContentLength) { this.responseContentLength = responseContentLength; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void setResponseContentLength() { chain.setResponseContentLength(10); assertThat(chain.getResponseContentLength()).isEqualTo(10); }
|
### Question:
DownloadChain implements Runnable { public void cancel() { if (finished.get() || this.currentThread == null) return; currentThread.interrupt(); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void cancel() { chain.currentThread = mock(Thread.class); chain.finished.set(true); chain.cancel(); verify(chain.currentThread, never()).interrupt(); chain.finished.set(false); chain.currentThread = null; chain.cancel(); chain.currentThread = mock(Thread.class); chain.cancel(); verify(chain.currentThread).interrupt(); }
|
### Question:
DownloadChain implements Runnable { @NonNull public BreakpointInfo getInfo() { return this.info; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void getInfo() { assertThat(chain.getInfo()).isEqualTo(info); }
|
### Question:
DownloadChain implements Runnable { @NonNull public DownloadCache getCache() { return cache; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void getCache() { assertThat(chain.getCache()).isEqualTo(cache); }
|
### Question:
DownloadChain implements Runnable { public synchronized void releaseConnection() { if (connection != null) { connection.release(); Util.d(TAG, "release connection " + connection + " task[" + task.getId() + "] block[" + blockIndex + "]"); } connection = null; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void releaseConnection() { final DownloadConnection connection = mock(DownloadConnection.class); chain.setConnection(connection); chain.releaseConnection(); verify(connection).release(); assertThat(chain.getConnection()).isNull(); }
|
### Question:
DownloadChain implements Runnable { public void resetConnectForRetry() { connectIndex = 1; releaseConnection(); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void resetConnectForRetry() { chain.connectIndex = 2; doNothing().when(chain).releaseConnection(); chain.resetConnectForRetry(); assertThat(chain.connectIndex).isEqualTo(1); verify(chain).releaseConnection(); }
|
### Question:
DownloadChain implements Runnable { @NonNull public DownloadStore getDownloadStore() { return store; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
@NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run(); }### Answer:
@Test public void getDownloadStore() { assertThat(chain.getDownloadStore()).isEqualTo(store); }
|
### Question:
BreakpointLocalCheck { @NonNull public ResumeFailedCause getCauseOrThrow() { if (!infoRight) { return INFO_DIRTY; } else if (!fileExist) { return FILE_NOT_EXIST; } else if (!outputStreamSupport) { return OUTPUT_STREAM_NOT_SUPPORT; } throw new IllegalStateException("No cause find with dirty: " + dirty); } BreakpointLocalCheck(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
long responseInstanceLength); boolean isDirty(); @NonNull ResumeFailedCause getCauseOrThrow(); boolean isInfoRightToResume(); boolean isOutputStreamSupportResume(); boolean isFileExistToResume(); void check(); @Override String toString(); }### Answer:
@Test public void getCauseOrThrow_infoDirty() { check.infoRight = false; check.fileExist = true; check.outputStreamSupport = true; assertThat(check.getCauseOrThrow()).isEqualTo(INFO_DIRTY); }
@Test public void getCauseOrThrow_fileNotExist() { check.infoRight = true; check.fileExist = false; check.outputStreamSupport = true; assertThat(check.getCauseOrThrow()).isEqualTo(FILE_NOT_EXIST); }
@Test public void getCauseOrThrow_outputStreamNotSupport() { check.infoRight = true; check.fileExist = true; check.outputStreamSupport = false; assertThat(check.getCauseOrThrow()).isEqualTo(OUTPUT_STREAM_NOT_SUPPORT); }
@Test(expected = IllegalStateException.class) public void getCauseOrThrow_notDirty() { check.infoRight = true; check.fileExist = true; check.outputStreamSupport = true; check.getCauseOrThrow(); }
|
### Question:
StatusUtil { public static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task) { return OkDownload.with().downloadDispatcher().findSameTask(task) != null; } static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task); static Status getStatus(@NonNull DownloadTask task); static Status getStatus(@NonNull String url, @NonNull String parentPath,
@Nullable String filename); static boolean isCompleted(@NonNull DownloadTask task); static Status isCompletedOrUnknown(@NonNull DownloadTask task); static boolean isCompleted(@NonNull String url, @NonNull String parentPath,
@Nullable String filename); @Nullable static BreakpointInfo getCurrentInfo(@NonNull String url,
@NonNull String parentPath,
@Nullable String filename); @Nullable static BreakpointInfo getCurrentInfo(@NonNull DownloadTask task); }### Answer:
@Test public void isSameTaskPendingOrRunning() throws IOException { mockOkDownload(); final DownloadTask task = mock(DownloadTask.class); final DownloadDispatcher dispatcher = OkDownload.with().downloadDispatcher(); when(dispatcher.findSameTask(task)).thenReturn(task); assertThat(StatusUtil.isSameTaskPendingOrRunning(task)).isTrue(); when(dispatcher.findSameTask(task)).thenReturn(null); assertThat(StatusUtil.isSameTaskPendingOrRunning(task)).isFalse(); }
|
### Question:
BreakpointLocalCheck { public boolean isOutputStreamSupportResume() { final boolean supportSeek = OkDownload.with().outputStreamFactory().supportSeek(); if (supportSeek) return true; if (info.getBlockCount() != 1) return false; if (OkDownload.with().processFileStrategy().isPreAllocateLength(task)) return false; return true; } BreakpointLocalCheck(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
long responseInstanceLength); boolean isDirty(); @NonNull ResumeFailedCause getCauseOrThrow(); boolean isInfoRightToResume(); boolean isOutputStreamSupportResume(); boolean isFileExistToResume(); void check(); @Override String toString(); }### Answer:
@Test public void isOutputStreamSupportResume_support() throws IOException { mockOkDownload(); final DownloadOutputStream.Factory factory = OkDownload.with().outputStreamFactory(); when(factory.supportSeek()).thenReturn(true); assertThat(check.isOutputStreamSupportResume()).isTrue(); when(factory.supportSeek()).thenReturn(false); when(info.getBlockCount()).thenReturn(1); final ProcessFileStrategy strategy = OkDownload.with().processFileStrategy(); when(strategy.isPreAllocateLength(task)).thenReturn(false); assertThat(check.isOutputStreamSupportResume()).isTrue(); }
@Test public void isOutputStreamSupportResume_notSupport() throws IOException { mockOkDownload(); final DownloadOutputStream.Factory factory = OkDownload.with().outputStreamFactory(); when(factory.supportSeek()).thenReturn(false); when(info.getBlockCount()).thenReturn(2); assertThat(check.isOutputStreamSupportResume()).isFalse(); when(info.getBlockCount()).thenReturn(1); final ProcessFileStrategy strategy = OkDownload.with().processFileStrategy(); doReturn(true).when(strategy).isPreAllocateLength(task); assertThat(check.isOutputStreamSupportResume()).isFalse(); }
|
### Question:
BreakpointLocalCheck { public boolean isFileExistToResume() { final Uri uri = task.getUri(); if (Util.isUriContentScheme(uri)) { return Util.getSizeFromContentUri(uri) > 0; } else { final File file = task.getFile(); return file != null && file.exists(); } } BreakpointLocalCheck(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
long responseInstanceLength); boolean isDirty(); @NonNull ResumeFailedCause getCauseOrThrow(); boolean isInfoRightToResume(); boolean isOutputStreamSupportResume(); boolean isFileExistToResume(); void check(); @Override String toString(); }### Answer:
@Test public void isFileExistToResume_contentUri() throws IOException { mockOkDownload(); final OkDownload okDownload = OkDownload.with(); final Context context = mock(Context.class); when(okDownload.context()).thenReturn(context); final ContentResolver resolver = mock(ContentResolver.class); when(context.getContentResolver()).thenReturn(resolver); when(task.getUri()).thenReturn(contentUri); assertThat(check.isFileExistToResume()).isFalse(); final Cursor cursor = mock(Cursor.class); when(resolver.query(contentUri, null, null, null, null)).thenReturn(cursor); doReturn(1L).when(cursor).getLong(anyInt()); assertThat(check.isFileExistToResume()).isTrue(); }
@Test public void isFileExistToResume_fileUri() { when(task.getUri()).thenReturn(fileUri); when(task.getFile()).thenReturn(null); assertThat(check.isFileExistToResume()).isFalse(); final File file = mock(File.class); when(task.getFile()).thenReturn(file); when(file.exists()).thenReturn(false); assertThat(check.isFileExistToResume()).isFalse(); when(file.exists()).thenReturn(true); assertThat(check.isFileExistToResume()).isTrue(); }
|
### Question:
DownloadCache { @NonNull MultiPointOutputStream getOutputStream() { if (outputStream == null) throw new IllegalArgumentException(); return outputStream; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAfterRun(); void setServerCanceled(IOException realCause); void setUnknownError(IOException realCause); void setPreAllocateFailed(IOException realCause); void catchException(IOException e); }### Answer:
@Test public void getOutputStream() throws Exception { assertThat(cache.getOutputStream()).isEqualTo(outputStream); }
|
### Question:
DownloadCache { void setRedirectLocation(String redirectLocation) { this.redirectLocation = redirectLocation; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAfterRun(); void setServerCanceled(IOException realCause); void setUnknownError(IOException realCause); void setPreAllocateFailed(IOException realCause); void catchException(IOException e); }### Answer:
@Test public void setRedirectLocation() throws Exception { final String redirectLocation = "redirectLocation"; cache.setRedirectLocation(redirectLocation); assertThat(cache.getRedirectLocation()).isEqualTo(redirectLocation); }
|
### Question:
DownloadCache { public void setPreconditionFailed(IOException realCause) { this.preconditionFailed = true; this.realCause = realCause; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAfterRun(); void setServerCanceled(IOException realCause); void setUnknownError(IOException realCause); void setPreAllocateFailed(IOException realCause); void catchException(IOException e); }### Answer:
@Test public void setPreconditionFailed() throws Exception { assertThat(cache.isInterrupt()).isFalse(); cache.setPreconditionFailed(realCause); assertThat(cache.getRealCause()).isEqualTo(realCause); assertThat(cache.isInterrupt()).isTrue(); }
|
### Question:
DownloadCache { void setUserCanceled() { this.userCanceled = true; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAfterRun(); void setServerCanceled(IOException realCause); void setUnknownError(IOException realCause); void setPreAllocateFailed(IOException realCause); void catchException(IOException e); }### Answer:
@Test public void setUserCanceled() throws Exception { assertThat(cache.isInterrupt()).isFalse(); assertThat(cache.isUserCanceled()).isFalse(); cache.setUserCanceled(); assertThat(cache.isUserCanceled()).isTrue(); assertThat(cache.isInterrupt()).isTrue(); }
|
### Question:
DownloadCache { public void setFileBusyAfterRun() { this.fileBusyAfterRun = true; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAfterRun(); void setServerCanceled(IOException realCause); void setUnknownError(IOException realCause); void setPreAllocateFailed(IOException realCause); void catchException(IOException e); }### Answer:
@Test public void setFileBusyAfterRun() throws Exception { assertThat(cache.isInterrupt()).isFalse(); cache.setFileBusyAfterRun(); assertThat(cache.isInterrupt()).isTrue(); }
|
### Question:
DownloadCache { public void setServerCanceled(IOException realCause) { this.serverCanceled = true; this.realCause = realCause; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAfterRun(); void setServerCanceled(IOException realCause); void setUnknownError(IOException realCause); void setPreAllocateFailed(IOException realCause); void catchException(IOException e); }### Answer:
@Test public void setServerCanceled() throws Exception { assertThat(cache.isInterrupt()).isFalse(); cache.setServerCanceled(realCause); assertThat(cache.isInterrupt()).isTrue(); }
|
### Question:
DownloadCache { public void setUnknownError(IOException realCause) { this.unknownError = true; this.realCause = realCause; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAfterRun(); void setServerCanceled(IOException realCause); void setUnknownError(IOException realCause); void setPreAllocateFailed(IOException realCause); void catchException(IOException e); }### Answer:
@Test public void setUnknownError() throws Exception { assertThat(cache.isInterrupt()).isFalse(); cache.setUnknownError(realCause); assertThat(cache.isInterrupt()).isTrue(); }
|
### Question:
DownloadSerialQueue extends DownloadListener2 implements Runnable { public synchronized void pause() { if (paused) { Util.w(TAG, "require pause this queue(remain " + taskList.size() + "), but" + "it has already been paused"); return; } paused = true; if (runningTask != null) { runningTask.cancel(); taskList.add(0, runningTask); runningTask = null; } } DownloadSerialQueue(); DownloadSerialQueue(DownloadListener listener, ArrayList<DownloadTask> taskList); DownloadSerialQueue(DownloadListener listener); void setListener(DownloadListener listener); synchronized void enqueue(DownloadTask task); synchronized void pause(); synchronized void resume(); int getWorkingTaskId(); int getWaitingTaskCount(); synchronized DownloadTask[] shutdown(); @Override void run(); @Override void taskStart(@NonNull DownloadTask task); @Override synchronized void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause,
@Nullable Exception realCause); }### Answer:
@Test public void pause() { serialQueue.pause(); assertThat(serialQueue.paused).isTrue(); }
@Test public void pause_isRunning_cancel() { serialQueue.runningTask = task1; serialQueue.pause(); verify(task1).cancel(); assertThat(taskList.get(0)).isEqualTo(task1); }
|
### Question:
DownloadCache { public void setPreAllocateFailed(IOException realCause) { this.preAllocateFailed = true; this.realCause = realCause; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAfterRun(); void setServerCanceled(IOException realCause); void setUnknownError(IOException realCause); void setPreAllocateFailed(IOException realCause); void catchException(IOException e); }### Answer:
@Test public void setPreAllocateFailed() throws Exception { assertThat(cache.isInterrupt()).isFalse(); cache.setPreAllocateFailed(realCause); assertThat(cache.isInterrupt()).isTrue(); }
|
### Question:
BreakpointRemoteCheck { boolean isTrialSpecialPass(int responseCode, long instanceLength, boolean isResumable) { if (responseCode == RANGE_NOT_SATISFIABLE && instanceLength >= 0 && isResumable) { return true; } return false; } BreakpointRemoteCheck(@NonNull DownloadTask task,
@NonNull BreakpointInfo info); @Override String toString(); @Nullable ResumeFailedCause getCause(); @NonNull ResumeFailedCause getCauseOrThrow(); boolean isResumable(); boolean isAcceptRange(); long getInstanceLength(); void check(); }### Answer:
@Test public void isTrialSpecialPass() { assertThat(check.isTrialSpecialPass(RANGE_NOT_SATISFIABLE, 0, true)).isTrue(); assertThat(check.isTrialSpecialPass(RANGE_NOT_SATISFIABLE, -1, true)).isFalse(); assertThat(check.isTrialSpecialPass(RANGE_NOT_SATISFIABLE, 0, false)).isFalse(); assertThat(check.isTrialSpecialPass(RANGE_NOT_SATISFIABLE, -1, false)).isFalse(); assertThat(check.isTrialSpecialPass(HttpURLConnection.HTTP_PARTIAL, 0, true)).isFalse(); }
|
### Question:
BreakpointRemoteCheck { @NonNull public ResumeFailedCause getCauseOrThrow() { if (failedCause == null) { throw new IllegalStateException("No cause find with resumable: " + resumable); } return this.failedCause; } BreakpointRemoteCheck(@NonNull DownloadTask task,
@NonNull BreakpointInfo info); @Override String toString(); @Nullable ResumeFailedCause getCause(); @NonNull ResumeFailedCause getCauseOrThrow(); boolean isResumable(); boolean isAcceptRange(); long getInstanceLength(); void check(); }### Answer:
@Test(expected = IllegalStateException.class) public void getCauseOrThrown() throws Exception { final ResumeFailedCause failedCause = mock(ResumeFailedCause.class); check.failedCause = failedCause; assertThat(check.getCauseOrThrow()).isEqualTo(failedCause); check.failedCause = null; check.getCauseOrThrow(); }
|
### Question:
DownloadStrategy { public boolean isUseMultiBlock(final boolean isAcceptRange) { if (!OkDownload.with().outputStreamFactory().supportSeek()) return false; return isAcceptRange; } ResumeAvailableResponseCheck resumeAvailableResponseCheck(
DownloadConnection.Connected connected,
int blockIndex,
BreakpointInfo info); int determineBlockCount(@NonNull DownloadTask task, long totalLength); long reuseIdledSameInfoThresholdBytes(); boolean inspectAnotherSameInfo(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
long instanceLength); boolean isUseMultiBlock(final boolean isAcceptRange); void inspectFilenameFromResume(@NonNull String filenameOnStore,
@NonNull DownloadTask task); void validFilenameFromResponse(@Nullable String responseFileName,
@NonNull DownloadTask task,
@NonNull BreakpointInfo info); boolean validFilenameFromStore(@NonNull DownloadTask task); void validInfoOnCompleted(@NonNull DownloadTask task, @NonNull DownloadStore store); @Nullable ResumeFailedCause getPreconditionFailedCause(int responseCode,
boolean isAlreadyProceed,
@NonNull BreakpointInfo info,
@Nullable String responseEtag); boolean isServerCanceled(int responseCode, boolean isAlreadyProceed); void inspectNetworkAvailable(); void inspectNetworkOnWifi(@NonNull DownloadTask task); }### Answer:
@Test public void isUseMultiBlock() throws IOException { mockOkDownload(); when(OkDownload.with().outputStreamFactory().supportSeek()).thenReturn(false); assertThat(strategy.isUseMultiBlock(false)).isFalse(); assertThat(strategy.isUseMultiBlock(true)).isFalse(); when(OkDownload.with().outputStreamFactory().supportSeek()).thenReturn(true); assertThat(strategy.isUseMultiBlock(true)).isTrue(); }
|
### Question:
DownloadStrategy { public void inspectFilenameFromResume(@NonNull String filenameOnStore, @NonNull DownloadTask task) { final String filename = task.getFilename(); if (Util.isEmpty(filename)) { task.getFilenameHolder().set(filenameOnStore); } } ResumeAvailableResponseCheck resumeAvailableResponseCheck(
DownloadConnection.Connected connected,
int blockIndex,
BreakpointInfo info); int determineBlockCount(@NonNull DownloadTask task, long totalLength); long reuseIdledSameInfoThresholdBytes(); boolean inspectAnotherSameInfo(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
long instanceLength); boolean isUseMultiBlock(final boolean isAcceptRange); void inspectFilenameFromResume(@NonNull String filenameOnStore,
@NonNull DownloadTask task); void validFilenameFromResponse(@Nullable String responseFileName,
@NonNull DownloadTask task,
@NonNull BreakpointInfo info); boolean validFilenameFromStore(@NonNull DownloadTask task); void validInfoOnCompleted(@NonNull DownloadTask task, @NonNull DownloadStore store); @Nullable ResumeFailedCause getPreconditionFailedCause(int responseCode,
boolean isAlreadyProceed,
@NonNull BreakpointInfo info,
@Nullable String responseEtag); boolean isServerCanceled(int responseCode, boolean isAlreadyProceed); void inspectNetworkAvailable(); void inspectNetworkOnWifi(@NonNull DownloadTask task); }### Answer:
@Test public void validFilenameResume() { final String taskFilename = "task-filename"; when(task.getFilename()).thenReturn(taskFilename); final DownloadStrategy.FilenameHolder filenameHolder = mock( DownloadStrategy.FilenameHolder.class); when(task.getFilenameHolder()).thenReturn(filenameHolder); final String storeFilename = "store-filename"; strategy.inspectFilenameFromResume(storeFilename, task); verify(filenameHolder, never()).set(anyString()); when(task.getFilename()).thenReturn(null); strategy.inspectFilenameFromResume(storeFilename, task); verify(filenameHolder).set(storeFilename); }
|
### Question:
DownloadStrategy { public boolean validFilenameFromStore(@NonNull DownloadTask task) { final String filename = OkDownload.with().breakpointStore() .getResponseFilename(task.getUrl()); if (filename == null) return false; task.getFilenameHolder().set(filename); return true; } ResumeAvailableResponseCheck resumeAvailableResponseCheck(
DownloadConnection.Connected connected,
int blockIndex,
BreakpointInfo info); int determineBlockCount(@NonNull DownloadTask task, long totalLength); long reuseIdledSameInfoThresholdBytes(); boolean inspectAnotherSameInfo(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
long instanceLength); boolean isUseMultiBlock(final boolean isAcceptRange); void inspectFilenameFromResume(@NonNull String filenameOnStore,
@NonNull DownloadTask task); void validFilenameFromResponse(@Nullable String responseFileName,
@NonNull DownloadTask task,
@NonNull BreakpointInfo info); boolean validFilenameFromStore(@NonNull DownloadTask task); void validInfoOnCompleted(@NonNull DownloadTask task, @NonNull DownloadStore store); @Nullable ResumeFailedCause getPreconditionFailedCause(int responseCode,
boolean isAlreadyProceed,
@NonNull BreakpointInfo info,
@Nullable String responseEtag); boolean isServerCanceled(int responseCode, boolean isAlreadyProceed); void inspectNetworkAvailable(); void inspectNetworkOnWifi(@NonNull DownloadTask task); }### Answer:
@Test public void validFilenameFromStore() { final DownloadStrategy.FilenameHolder holder = new DownloadStrategy.FilenameHolder(); when(task.getUrl()).thenReturn("url"); when(task.getFilenameHolder()).thenReturn(holder); final BreakpointStore store = OkDownload.with().breakpointStore(); doReturn(null).when(store).getResponseFilename("url"); assertThat(strategy.validFilenameFromStore(task)).isFalse(); assertThat(holder.get()).isNull(); doReturn("filename").when(store).getResponseFilename("url"); assertThat(strategy.validFilenameFromStore(task)).isTrue(); assertThat(holder.get()).isEqualTo("filename"); }
|
### Question:
ConnectTrial { public long getInstanceLength() { return this.instanceLength; } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getResponseFilename(); int getResponseCode(); boolean isEtagOverdue(); }### Answer:
@Test public void getInstanceLength() throws Exception { when(connected.getResponseHeaderField(CONTENT_RANGE)) .thenReturn("bytes 21010-47021/47022"); connectTrial.executeTrial(); assertThat(connectTrial.getInstanceLength()).isEqualTo(47022L); assertThat(connectTrial.isChunked()).isFalse(); when(connected.getResponseHeaderField(CONTENT_RANGE)) .thenReturn(null); connectTrial.executeTrial(); assertThat(connectTrial.getInstanceLength()).isEqualTo(CHUNKED_CONTENT_LENGTH); assertThat(connectTrial.isChunked()).isTrue(); }
|
### Question:
ConnectTrial { public boolean isAcceptRange() { return this.acceptRange; } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getResponseFilename(); int getResponseCode(); boolean isEtagOverdue(); }### Answer:
@Test public void isAcceptRange() throws Exception { when(connected.getResponseCode()).thenReturn(HttpURLConnection.HTTP_PARTIAL); connectTrial.executeTrial(); assertThat(connectTrial.isAcceptRange()).isTrue(); when(connected.getResponseCode()).thenReturn(0); connectTrial.executeTrial(); assertThat(connectTrial.isAcceptRange()).isFalse(); when(connected.getResponseHeaderField(ACCEPT_RANGES)).thenReturn("bytes"); connectTrial.executeTrial(); assertThat(connectTrial.isAcceptRange()).isTrue(); }
|
### Question:
ConnectTrial { public boolean isEtagOverdue() { return info.getEtag() != null && !info.getEtag().equals(responseEtag); } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getResponseFilename(); int getResponseCode(); boolean isEtagOverdue(); }### Answer:
@Test public void isEtagOverdue() throws Exception { when(connected.getResponseHeaderField(ETAG)).thenReturn(etag); connectTrial.executeTrial(); assertThat(connectTrial.isEtagOverdue()).isFalse(); when(connected.getResponseHeaderField(ETAG)).thenReturn("newEtag"); connectTrial.executeTrial(); assertThat(connectTrial.isEtagOverdue()).isTrue(); assertThat(connectTrial.getResponseEtag()).isEqualTo("newEtag"); }
|
### Question:
ConnectTrial { @Nullable public String getResponseFilename() { return responseFilename; } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getResponseFilename(); int getResponseCode(); boolean isEtagOverdue(); }### Answer:
@Test public void getResponseFilename() throws IOException { connectTrial.executeTrial(); assertThat(connectTrial.getResponseFilename()).isNull(); when(connected.getResponseHeaderField(CONTENT_DISPOSITION)) .thenReturn("attachment; filename=\"hello world\""); connectTrial.executeTrial(); assertThat(connectTrial.getResponseFilename()).isEqualTo("hello world"); when(connected.getResponseHeaderField(CONTENT_DISPOSITION)) .thenReturn("attachment; filename=\"hello world\""); connectTrial.executeTrial(); assertThat(connectTrial.getResponseFilename()).isEqualTo("hello world"); when(connected.getResponseHeaderField(CONTENT_DISPOSITION)) .thenReturn("attachment; filename=genome.jpeg\nabc"); connectTrial.executeTrial(); assertThat(connectTrial.getResponseFilename()).isEqualTo("genome.jpeg"); when(connected.getResponseHeaderField(CONTENT_DISPOSITION)) .thenReturn("attachment; filename=../data/data/genome.png"); thrown.expect(DownloadSecurityException.class); thrown.expectMessage("The filename [../data/data/genome.png] from the response is not " + "allowable, because it contains '../', which can raise the directory traversal " + "vulnerability"); connectTrial.executeTrial(); when(connected.getResponseHeaderField(CONTENT_DISPOSITION)) .thenReturn("attachment; filename=a/b/../abc"); thrown.expect(DownloadSecurityException.class); thrown.expectMessage("The filename [a/b/../abc] from the response is not " + "allowable, because it contains '../', which can raise the directory traversal " + "vulnerability"); connectTrial.executeTrial(); }
|
### Question:
ConnectTrial { public int getResponseCode() { return responseCode; } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getResponseFilename(); int getResponseCode(); boolean isEtagOverdue(); }### Answer:
@Test public void getResponseCode() throws Exception { when(connected.getResponseCode()).thenReturn(1); connectTrial.executeTrial(); assertThat(connectTrial.getResponseCode()).isEqualTo(1); }
|
### Question:
UnifiedListenerManager { public synchronized void detachListener(int id) { realListenerMap.remove(id); } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int id); synchronized void removeAutoRemoveListenersWhenTaskEnd(int id); synchronized void detachListener(DownloadListener listener); synchronized boolean detachListener(@NonNull DownloadTask task,
DownloadListener listener); synchronized void attachListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void attachAndEnqueueIfNotRun(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void enqueueTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void executeTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); @NonNull DownloadListener getHostListener(); }### Answer:
@Test public void detachListener() { final ArrayList<DownloadListener> list = new ArrayList<>(); list.add(listener); listenerManager.realListenerMap.put(1, list); final DownloadTask task = mockTask(1); listenerManager.detachListener(task, listener); assertThat(listenerManager.realListenerMap.size()).isZero(); list.add(listener); listenerManager.realListenerMap.put(2, list); assertThat(listenerManager.realListenerMap.size()).isEqualTo(1); listenerManager.detachListener(listener); assertThat(listenerManager.realListenerMap.size()).isZero(); }
@Test public void detachListener_taskId() { final ArrayList<DownloadListener> listenerList = new ArrayList<>(); listenerList.add(mock(DownloadListener.class)); listenerManager.realListenerMap.put(1, listenerList); listenerManager.detachListener(1); assertThat(listenerManager.realListenerMap.size()).isZero(); }
|
### Question:
UnifiedListenerManager { public synchronized void attachListener(@NonNull DownloadTask task, @NonNull DownloadListener listener) { final int id = task.getId(); ArrayList<DownloadListener> listenerList = realListenerMap.get(id); if (listenerList == null) { listenerList = new ArrayList<>(); realListenerMap.put(id, listenerList); } if (!listenerList.contains(listener)) { listenerList.add(listener); if (listener instanceof ListenerAssist) { ((ListenerAssist) listener).setAlwaysRecoverAssistModelIfNotSet(true); } } } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int id); synchronized void removeAutoRemoveListenersWhenTaskEnd(int id); synchronized void detachListener(DownloadListener listener); synchronized boolean detachListener(@NonNull DownloadTask task,
DownloadListener listener); synchronized void attachListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void attachAndEnqueueIfNotRun(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void enqueueTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void executeTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); @NonNull DownloadListener getHostListener(); }### Answer:
@Test public void attachListener() { final DownloadTask task = mockTask(2); listenerManager.attachListener(task, listener); assertThat(listenerManager.realListenerMap.size()).isEqualTo(1); assertThat(listenerManager.realListenerMap.get(2)).containsExactly(listener); final DownloadListener1 listener1 = mock(DownloadListener1.class); listenerManager.attachListener(task, listener1); verify(listener1).setAlwaysRecoverAssistModelIfNotSet(eq(true)); }
|
### Question:
UnifiedListenerManager { public synchronized void attachAndEnqueueIfNotRun(@NonNull DownloadTask task, @NonNull DownloadListener listener) { attachListener(task, listener); if (!isTaskPendingOrRunning(task)) { task.enqueue(hostListener); } } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int id); synchronized void removeAutoRemoveListenersWhenTaskEnd(int id); synchronized void detachListener(DownloadListener listener); synchronized boolean detachListener(@NonNull DownloadTask task,
DownloadListener listener); synchronized void attachListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void attachAndEnqueueIfNotRun(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void enqueueTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void executeTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); @NonNull DownloadListener getHostListener(); }### Answer:
@Test public void attachAndEnqueueIfNotRun() { final DownloadTask task = mockTask(1); doNothing().when(listenerManager).attachListener(eq(task), eq(listener)); doReturn(true).when(listenerManager).isTaskPendingOrRunning(eq(task)); listenerManager.attachAndEnqueueIfNotRun(task, listener); assertThat(listenerManager.realListenerMap.size()).isZero(); verify(task, never()).enqueue(eq(listenerManager.hostListener)); verify(listenerManager).attachListener(eq(task), eq(listener)); doReturn(false).when(listenerManager).isTaskPendingOrRunning(eq(task)); listenerManager.attachAndEnqueueIfNotRun(task, listener); verify(task).enqueue(eq(listenerManager.hostListener)); verify(listenerManager, times(2)).attachListener(eq(task), eq(listener)); }
|
### Question:
UnifiedListenerManager { public synchronized void executeTaskWithUnifiedListener(@NonNull DownloadTask task, @NonNull DownloadListener listener) { attachListener(task, listener); task.execute(hostListener); } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int id); synchronized void removeAutoRemoveListenersWhenTaskEnd(int id); synchronized void detachListener(DownloadListener listener); synchronized boolean detachListener(@NonNull DownloadTask task,
DownloadListener listener); synchronized void attachListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void attachAndEnqueueIfNotRun(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void enqueueTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void executeTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); @NonNull DownloadListener getHostListener(); }### Answer:
@Test public void executeTaskWithUnifiedListener() { final DownloadTask task = mockTask(1); doNothing().when(listenerManager).attachListener(eq(task), eq(listener)); doNothing().when(task).execute(eq(listenerManager.hostListener)); listenerManager.executeTaskWithUnifiedListener(task, listener); verify(listenerManager).attachListener(eq(task), eq(listener)); verify(task).execute(eq(listenerManager.hostListener)); }
|
### Question:
UnifiedListenerManager { public synchronized void addAutoRemoveListenersWhenTaskEnd(int id) { if (autoRemoveListenerIdList.contains(id)) return; autoRemoveListenerIdList.add(id); } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int id); synchronized void removeAutoRemoveListenersWhenTaskEnd(int id); synchronized void detachListener(DownloadListener listener); synchronized boolean detachListener(@NonNull DownloadTask task,
DownloadListener listener); synchronized void attachListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void attachAndEnqueueIfNotRun(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void enqueueTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void executeTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); @NonNull DownloadListener getHostListener(); }### Answer:
@Test public void addAutoRemoveListenersWhenTaskEnd() { listenerManager.addAutoRemoveListenersWhenTaskEnd(1); listenerManager.addAutoRemoveListenersWhenTaskEnd(1); assertThat(listenerManager.autoRemoveListenerIdList).containsExactly(1); }
|
### Question:
UnifiedListenerManager { public synchronized void removeAutoRemoveListenersWhenTaskEnd(int id) { autoRemoveListenerIdList.remove((Integer) id); } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int id); synchronized void removeAutoRemoveListenersWhenTaskEnd(int id); synchronized void detachListener(DownloadListener listener); synchronized boolean detachListener(@NonNull DownloadTask task,
DownloadListener listener); synchronized void attachListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void attachAndEnqueueIfNotRun(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void enqueueTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); synchronized void executeTaskWithUnifiedListener(@NonNull DownloadTask task,
@NonNull DownloadListener listener); @NonNull DownloadListener getHostListener(); }### Answer:
@Test public void removeAutoRemoveListenersWhenTaskEnd() { listenerManager.autoRemoveListenerIdList.add(1); listenerManager.removeAutoRemoveListenersWhenTaskEnd(1); assertThat(listenerManager.autoRemoveListenerIdList).isEmpty(); }
|
### Question:
RedirectUtil { public static boolean isRedirect(int code) { return code == HttpURLConnection.HTTP_MOVED_PERM || code == HttpURLConnection.HTTP_MOVED_TEMP || code == HttpURLConnection.HTTP_SEE_OTHER || code == HttpURLConnection.HTTP_MULT_CHOICE || code == HTTP_TEMPORARY_REDIRECT || code == HTTP_PERMANENT_REDIRECT; } static boolean isRedirect(int code); @NonNull static String getRedirectedUrl(DownloadConnection.Connected connected, int responseCode); static final int MAX_REDIRECT_TIMES; }### Answer:
@Test public void isRedirect() { assertTrue(RedirectUtil.isRedirect(HttpURLConnection.HTTP_MOVED_PERM)); assertTrue(RedirectUtil.isRedirect(HttpURLConnection.HTTP_MOVED_TEMP)); assertTrue(RedirectUtil.isRedirect(HttpURLConnection.HTTP_SEE_OTHER)); assertTrue(RedirectUtil.isRedirect(HttpURLConnection.HTTP_MULT_CHOICE)); assertTrue(RedirectUtil.isRedirect(RedirectUtil.HTTP_TEMPORARY_REDIRECT)); assertTrue(RedirectUtil.isRedirect(RedirectUtil.HTTP_PERMANENT_REDIRECT)); assertFalse(RedirectUtil.isRedirect(HttpsURLConnection.HTTP_ACCEPTED)); }
|
### Question:
RedirectUtil { @NonNull public static String getRedirectedUrl(DownloadConnection.Connected connected, int responseCode) throws IOException { String url = connected.getResponseHeaderField("Location"); if (url == null) { throw new ProtocolException( "Response code is " + responseCode + " but can't find Location field"); } return url; } static boolean isRedirect(int code); @NonNull static String getRedirectedUrl(DownloadConnection.Connected connected, int responseCode); static final int MAX_REDIRECT_TIMES; }### Answer:
@Test public void getRedirectedUrl_thrownProtocolException() throws IOException { thrown.expect(ProtocolException.class); thrown.expectMessage("Response code is 302 but can't find Location field"); final DownloadConnection.Connected connected = mock(DownloadConnection.Connected.class); when(connected.getResponseHeaderField("Location")).thenReturn(null); RedirectUtil.getRedirectedUrl(connected, 302); }
@Test public void getRedirectUrl() throws IOException { final String redirectUrl = "http: final DownloadConnection.Connected connected = mock(DownloadConnection.Connected.class); when(connected.getResponseHeaderField("Location")).thenReturn(redirectUrl); assertEquals(RedirectUtil.getRedirectedUrl(connected, 302), redirectUrl); }
|
### Question:
OkDownloadProvider extends ContentProvider { @Override public boolean onCreate() { context = getContext(); return true; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection,
@Nullable String selection, @Nullable String[] selectionArgs,
@Nullable String sortOrder); @Nullable @Override String getType(@NonNull Uri uri); @Nullable @Override Uri insert(@NonNull Uri uri, @Nullable ContentValues values); @Override int delete(@NonNull Uri uri, @Nullable String selection,
@Nullable String[] selectionArgs); @Override int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
@Nullable String[] selectionArgs); @SuppressFBWarnings(value = "ST")
@SuppressLint("StaticFieldLeak")
static Context context; }### Answer:
@Test public void onCreate() { assertThat(provider.onCreate()).isTrue(); }
|
### Question:
ResumeFailedException extends IOException { public ResumeFailedCause getResumeFailedCause() { return resumeFailedCause; } ResumeFailedException(ResumeFailedCause cause); ResumeFailedCause getResumeFailedCause(); }### Answer:
@Test public void construct() { final ResumeFailedCause cause = ResumeFailedCause.FILE_NOT_EXIST; ResumeFailedException exception = new ResumeFailedException(cause); assertThat(exception.getMessage()).isEqualTo("Resume failed because of " + cause); assertThat(exception.getResumeFailedCause()).isEqualTo(cause); }
|
### Question:
OkDownloadProvider extends ContentProvider { @Nullable @Override public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { return null; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection,
@Nullable String selection, @Nullable String[] selectionArgs,
@Nullable String sortOrder); @Nullable @Override String getType(@NonNull Uri uri); @Nullable @Override Uri insert(@NonNull Uri uri, @Nullable ContentValues values); @Override int delete(@NonNull Uri uri, @Nullable String selection,
@Nullable String[] selectionArgs); @Override int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
@Nullable String[] selectionArgs); @SuppressFBWarnings(value = "ST")
@SuppressLint("StaticFieldLeak")
static Context context; }### Answer:
@Test public void query() { assertThat(provider.query(uri, null, null, null, null)).isNull(); }
|
### Question:
OkDownloadProvider extends ContentProvider { @Nullable @Override public String getType(@NonNull Uri uri) { return null; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection,
@Nullable String selection, @Nullable String[] selectionArgs,
@Nullable String sortOrder); @Nullable @Override String getType(@NonNull Uri uri); @Nullable @Override Uri insert(@NonNull Uri uri, @Nullable ContentValues values); @Override int delete(@NonNull Uri uri, @Nullable String selection,
@Nullable String[] selectionArgs); @Override int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
@Nullable String[] selectionArgs); @SuppressFBWarnings(value = "ST")
@SuppressLint("StaticFieldLeak")
static Context context; }### Answer:
@Test public void getType() { assertThat(provider.getType(uri)).isNull(); }
|
### Question:
OkDownloadProvider extends ContentProvider { @Nullable @Override public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) { return null; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection,
@Nullable String selection, @Nullable String[] selectionArgs,
@Nullable String sortOrder); @Nullable @Override String getType(@NonNull Uri uri); @Nullable @Override Uri insert(@NonNull Uri uri, @Nullable ContentValues values); @Override int delete(@NonNull Uri uri, @Nullable String selection,
@Nullable String[] selectionArgs); @Override int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
@Nullable String[] selectionArgs); @SuppressFBWarnings(value = "ST")
@SuppressLint("StaticFieldLeak")
static Context context; }### Answer:
@Test public void insert() { assertThat(provider.insert(uri, null)).isNull(); }
|
### Question:
OkDownloadProvider extends ContentProvider { @Override public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) { return 0; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection,
@Nullable String selection, @Nullable String[] selectionArgs,
@Nullable String sortOrder); @Nullable @Override String getType(@NonNull Uri uri); @Nullable @Override Uri insert(@NonNull Uri uri, @Nullable ContentValues values); @Override int delete(@NonNull Uri uri, @Nullable String selection,
@Nullable String[] selectionArgs); @Override int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
@Nullable String[] selectionArgs); @SuppressFBWarnings(value = "ST")
@SuppressLint("StaticFieldLeak")
static Context context; }### Answer:
@Test public void delete() { assertThat(provider.delete(uri, null, null)).isZero(); }
|
### Question:
OkDownloadProvider extends ContentProvider { @Override public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) { return 0; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection,
@Nullable String selection, @Nullable String[] selectionArgs,
@Nullable String sortOrder); @Nullable @Override String getType(@NonNull Uri uri); @Nullable @Override Uri insert(@NonNull Uri uri, @Nullable ContentValues values); @Override int delete(@NonNull Uri uri, @Nullable String selection,
@Nullable String[] selectionArgs); @Override int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
@Nullable String[] selectionArgs); @SuppressFBWarnings(value = "ST")
@SuppressLint("StaticFieldLeak")
static Context context; }### Answer:
@Test public void update() { assertThat(provider.update(uri, null, null, null)).isZero(); }
|
### Question:
DownloadContext { public void startOnSerial(DownloadListener listener) { start(listener, true); } DownloadContext(@NonNull DownloadTask[] tasks,
@Nullable DownloadContextListener contextListener,
@NonNull QueueSet set,
@NonNull Handler uiHandler); DownloadContext(@NonNull DownloadTask[] tasks,
@Nullable DownloadContextListener contextListener,
@NonNull QueueSet set); boolean isStarted(); @SuppressFBWarnings(value = "EI", justification = "user must know change this array will effect internal job") DownloadTask[] getTasks(); void startOnSerial(DownloadListener listener); void startOnParallel(DownloadListener listener); void start(@Nullable final DownloadListener listener, boolean isSerial); AlterContext alter(); void stop(); Builder toBuilder(); }### Answer:
@Test public void startOnSerial() { doNothing().when(context).start(eq(listener), anyBoolean()); context.startOnSerial(listener); verify(context).start(eq(listener), eq(true)); }
|
### Question:
DownloadContext { public void startOnParallel(DownloadListener listener) { start(listener, false); } DownloadContext(@NonNull DownloadTask[] tasks,
@Nullable DownloadContextListener contextListener,
@NonNull QueueSet set,
@NonNull Handler uiHandler); DownloadContext(@NonNull DownloadTask[] tasks,
@Nullable DownloadContextListener contextListener,
@NonNull QueueSet set); boolean isStarted(); @SuppressFBWarnings(value = "EI", justification = "user must know change this array will effect internal job") DownloadTask[] getTasks(); void startOnSerial(DownloadListener listener); void startOnParallel(DownloadListener listener); void start(@Nullable final DownloadListener listener, boolean isSerial); AlterContext alter(); void stop(); Builder toBuilder(); }### Answer:
@Test public void startOnParallel() { doNothing().when(context).start(eq(listener), anyBoolean()); context.startOnParallel(listener); verify(context).start(eq(listener), eq(false)); }
|
### Question:
DownloadContext { public void stop() { if (started) OkDownload.with().downloadDispatcher().cancel(tasks); started = false; } DownloadContext(@NonNull DownloadTask[] tasks,
@Nullable DownloadContextListener contextListener,
@NonNull QueueSet set,
@NonNull Handler uiHandler); DownloadContext(@NonNull DownloadTask[] tasks,
@Nullable DownloadContextListener contextListener,
@NonNull QueueSet set); boolean isStarted(); @SuppressFBWarnings(value = "EI", justification = "user must know change this array will effect internal job") DownloadTask[] getTasks(); void startOnSerial(DownloadListener listener); void startOnParallel(DownloadListener listener); void start(@Nullable final DownloadListener listener, boolean isSerial); AlterContext alter(); void stop(); Builder toBuilder(); }### Answer:
@Test public void stop() { context.started = true; context.stop(); assertThat(context.isStarted()).isFalse(); verify(OkDownload.with().downloadDispatcher()).cancel(tasks); }
|
### Question:
DownloadContext { public AlterContext alter() { return new AlterContext(this); } DownloadContext(@NonNull DownloadTask[] tasks,
@Nullable DownloadContextListener contextListener,
@NonNull QueueSet set,
@NonNull Handler uiHandler); DownloadContext(@NonNull DownloadTask[] tasks,
@Nullable DownloadContextListener contextListener,
@NonNull QueueSet set); boolean isStarted(); @SuppressFBWarnings(value = "EI", justification = "user must know change this array will effect internal job") DownloadTask[] getTasks(); void startOnSerial(DownloadListener listener); void startOnParallel(DownloadListener listener); void start(@Nullable final DownloadListener listener, boolean isSerial); AlterContext alter(); void stop(); Builder toBuilder(); }### Answer:
@Test public void replaceTask() { final DownloadTask oldTask = tasks[0]; final DownloadTask newTask = mock(DownloadTask.class); context.alter().replaceTask(oldTask, newTask); assertThat(tasks[0]).isEqualTo(newTask); }
|
### Question:
DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public void release() { request = null; if (response != null) response.close(); response = null; } DownloadOkHttp3Connection(@NonNull OkHttpClient client,
@NonNull Request.Builder requestBuilder); DownloadOkHttp3Connection(@NonNull OkHttpClient client, @NonNull String url); @Override void addHeader(String name, String value); @Override Connected execute(); @Override void release(); @Override Map<String, List<String>> getRequestProperties(); @Override String getRequestProperty(String key); @Override int getResponseCode(); @Override InputStream getInputStream(); @Override boolean setRequestMethod(@NonNull String method); @Override Map<String, List<String>> getResponseHeaderFields(); @Override String getResponseHeaderField(String name); @Override String getRedirectLocation(); }### Answer:
@Test public void release() throws Exception { final Call call = mock(Call.class); when(client.newCall(any(Request.class))).thenReturn(call); final ResponseBody body = mock(ResponseBody.class); connection.response = createResponseBuilder() .body(body).build(); connection.release(); verify(body).close(); assertThat(connection.response).isNull(); }
|
### Question:
ServerCanceledException extends IOException { public int getResponseCode() { return responseCode; } ServerCanceledException(int responseCode, long currentOffset); int getResponseCode(); }### Answer:
@Test public void construct() { int responseCode = 1; long offset = 2; ServerCanceledException exception = new ServerCanceledException(responseCode, offset); assertThat(exception.getMessage()) .isEqualTo("Response code can't handled on internal " + responseCode + " with current offset " + offset); assertThat(exception.getResponseCode()).isEqualTo(responseCode); }
|
### Question:
DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public InputStream getInputStream() throws IOException { if (response == null) throw new IOException("Please invoke execute first!"); final ResponseBody body = response.body(); if (body == null) throw new IOException("no body found on response!"); return body.byteStream(); } DownloadOkHttp3Connection(@NonNull OkHttpClient client,
@NonNull Request.Builder requestBuilder); DownloadOkHttp3Connection(@NonNull OkHttpClient client, @NonNull String url); @Override void addHeader(String name, String value); @Override Connected execute(); @Override void release(); @Override Map<String, List<String>> getRequestProperties(); @Override String getRequestProperty(String key); @Override int getResponseCode(); @Override InputStream getInputStream(); @Override boolean setRequestMethod(@NonNull String method); @Override Map<String, List<String>> getResponseHeaderFields(); @Override String getResponseHeaderField(String name); @Override String getRedirectLocation(); }### Answer:
@Test(expected = IOException.class) public void getInputStream_responseIsNull_throwException() throws IOException { connection.getInputStream(); }
|
### Question:
DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public Connected execute() throws IOException { request = requestBuilder.build(); response = client.newCall(request).execute(); return this; } DownloadOkHttp3Connection(@NonNull OkHttpClient client,
@NonNull Request.Builder requestBuilder); DownloadOkHttp3Connection(@NonNull OkHttpClient client, @NonNull String url); @Override void addHeader(String name, String value); @Override Connected execute(); @Override void release(); @Override Map<String, List<String>> getRequestProperties(); @Override String getRequestProperty(String key); @Override int getResponseCode(); @Override InputStream getInputStream(); @Override boolean setRequestMethod(@NonNull String method); @Override Map<String, List<String>> getResponseHeaderFields(); @Override String getResponseHeaderField(String name); @Override String getRedirectLocation(); }### Answer:
@Test public void execute() throws IOException { final Call call = mock(Call.class); when(client.newCall(any(Request.class))).thenReturn(call); final Request request = new Request.Builder() .url("http: .build(); final Response response = createResponseBuilder().build(); when(call.execute()).thenReturn(response); final Request.Builder builder = mock(Request.Builder.class); when(builder.build()).thenReturn(request); DownloadOkHttp3Connection connection = new DownloadOkHttp3Connection(client, builder); connection.execute(); verify(client).newCall(eq(request)); verify(call).execute(); }
|
### Question:
DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public int getResponseCode() throws IOException { if (response == null) throw new IOException("Please invoke execute first!"); return response.code(); } DownloadOkHttp3Connection(@NonNull OkHttpClient client,
@NonNull Request.Builder requestBuilder); DownloadOkHttp3Connection(@NonNull OkHttpClient client, @NonNull String url); @Override void addHeader(String name, String value); @Override Connected execute(); @Override void release(); @Override Map<String, List<String>> getRequestProperties(); @Override String getRequestProperty(String key); @Override int getResponseCode(); @Override InputStream getInputStream(); @Override boolean setRequestMethod(@NonNull String method); @Override Map<String, List<String>> getResponseHeaderFields(); @Override String getResponseHeaderField(String name); @Override String getRedirectLocation(); }### Answer:
@Test(expected = IOException.class) public void getResponseCode_responseIsNull_throwException() throws IOException { connection.getResponseCode(); }
|
### Question:
DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public boolean setRequestMethod(@NonNull String method) throws ProtocolException { this.requestBuilder.method(method, null); return true; } DownloadOkHttp3Connection(@NonNull OkHttpClient client,
@NonNull Request.Builder requestBuilder); DownloadOkHttp3Connection(@NonNull OkHttpClient client, @NonNull String url); @Override void addHeader(String name, String value); @Override Connected execute(); @Override void release(); @Override Map<String, List<String>> getRequestProperties(); @Override String getRequestProperty(String key); @Override int getResponseCode(); @Override InputStream getInputStream(); @Override boolean setRequestMethod(@NonNull String method); @Override Map<String, List<String>> getResponseHeaderFields(); @Override String getResponseHeaderField(String name); @Override String getRedirectLocation(); }### Answer:
@Test public void setRequestMethod() throws ProtocolException { final Request.Builder builder = mock(Request.Builder.class); final DownloadOkHttp3Connection connection = new DownloadOkHttp3Connection(client, builder); assertThat(connection.setRequestMethod("HEAD")).isTrue(); verify(builder).method(eq("HEAD"), nullable(RequestBody.class)); }
|
### Question:
DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public String getRedirectLocation() { final Response priorRes = response.priorResponse(); if (priorRes != null && response.isSuccessful() && RedirectUtil.isRedirect(priorRes.code())) { return response.request().url().toString(); } return null; } DownloadOkHttp3Connection(@NonNull OkHttpClient client,
@NonNull Request.Builder requestBuilder); DownloadOkHttp3Connection(@NonNull OkHttpClient client, @NonNull String url); @Override void addHeader(String name, String value); @Override Connected execute(); @Override void release(); @Override Map<String, List<String>> getRequestProperties(); @Override String getRequestProperty(String key); @Override int getResponseCode(); @Override InputStream getInputStream(); @Override boolean setRequestMethod(@NonNull String method); @Override Map<String, List<String>> getResponseHeaderFields(); @Override String getResponseHeaderField(String name); @Override String getRedirectLocation(); }### Answer:
@Test public void getRedirectLocation() { final Response.Builder responseBuilder = createResponseBuilder(); connection.response = responseBuilder.build(); assertThat(connection.getRedirectLocation()).isEqualTo(null); final Response priorRes = new Response.Builder() .protocol(Protocol.HTTP_1_1) .code(302) .request(new Request.Builder().url("http: .message("message") .build(); connection.response = responseBuilder .priorResponse(priorRes) .build(); assertThat(connection.getRedirectLocation()).isEqualTo("http: }
|
### Question:
BreakpointInfoRow { public BreakpointInfo toInfo() { final BreakpointInfo info = new BreakpointInfo(id, url, new File(parentPath), filename, taskOnlyProvidedParentPath); info.setEtag(etag); info.setChunked(chunked); return info; } BreakpointInfoRow(Cursor cursor); int getId(); String getUrl(); String getEtag(); String getParentPath(); String getFilename(); boolean isTaskOnlyProvidedParentPath(); boolean isChunked(); BreakpointInfo toInfo(); }### Answer:
@Test public void toInfo() { final BreakpointInfo info = breakpointInfoRow.toInfo(); assertThat(info.id).isEqualTo(10); assertThat(info.getUrl()).isEqualTo("url"); assertThat(info.getEtag()).isEqualTo("etag"); assertThat(info.parentFile).isEqualTo(new File("p-path")); assertThat(info.getFilename()).isNull(); assertThat(info.isTaskOnlyProvidedParentPath()).isTrue(); assertThat(info.isChunked()).isFalse(); }
|
### Question:
BreakpointStoreOnSQLite implements DownloadStore { @Nullable @Override public BreakpointInfo getAfterCompleted(int id) { return null; } BreakpointStoreOnSQLite(BreakpointSQLiteHelper helper, BreakpointStoreOnCache onCache); BreakpointStoreOnSQLite(Context context); @Nullable @Override BreakpointInfo get(int id); @NonNull @Override BreakpointInfo createAndInsert(@NonNull DownloadTask task); @Override void onTaskStart(int id); @Override void onSyncToFilesystemSuccess(@NonNull BreakpointInfo info, int blockIndex,
long increaseLength); @Override boolean update(@NonNull BreakpointInfo breakpointInfo); @Override void onTaskEnd(int id, @NonNull EndCause cause, @Nullable Exception exception); @Nullable @Override BreakpointInfo getAfterCompleted(int id); @Override boolean markFileDirty(int id); @Override boolean markFileClear(int id); @Override void remove(int id); @Override int findOrCreateId(@NonNull DownloadTask task); @Nullable @Override BreakpointInfo findAnotherInfoFromCompare(@NonNull DownloadTask task,
@NonNull BreakpointInfo ignored); @Override boolean isOnlyMemoryCache(); @Override boolean isFileDirty(int id); @Nullable @Override String getResponseFilename(String url); @NonNull DownloadStore createRemitSelf(); }### Answer:
@Test public void getAfterCompleted() { assertThat(store.getAfterCompleted(1)).isNull(); }
|
### Question:
BreakpointStoreOnSQLite implements DownloadStore { @Override public boolean markFileDirty(int id) { if (onCache.markFileDirty(id)) { helper.markFileDirty(id); return true; } return false; } BreakpointStoreOnSQLite(BreakpointSQLiteHelper helper, BreakpointStoreOnCache onCache); BreakpointStoreOnSQLite(Context context); @Nullable @Override BreakpointInfo get(int id); @NonNull @Override BreakpointInfo createAndInsert(@NonNull DownloadTask task); @Override void onTaskStart(int id); @Override void onSyncToFilesystemSuccess(@NonNull BreakpointInfo info, int blockIndex,
long increaseLength); @Override boolean update(@NonNull BreakpointInfo breakpointInfo); @Override void onTaskEnd(int id, @NonNull EndCause cause, @Nullable Exception exception); @Nullable @Override BreakpointInfo getAfterCompleted(int id); @Override boolean markFileDirty(int id); @Override boolean markFileClear(int id); @Override void remove(int id); @Override int findOrCreateId(@NonNull DownloadTask task); @Nullable @Override BreakpointInfo findAnotherInfoFromCompare(@NonNull DownloadTask task,
@NonNull BreakpointInfo ignored); @Override boolean isOnlyMemoryCache(); @Override boolean isFileDirty(int id); @Nullable @Override String getResponseFilename(String url); @NonNull DownloadStore createRemitSelf(); }### Answer:
@Test public void markFileDirty() { doReturn(false).when(onCache).markFileDirty(1); assertThat(store.markFileDirty(1)).isFalse(); verify(helper, never()).markFileDirty(eq(1)); doReturn(true).when(onCache).markFileDirty(1); assertThat(store.markFileDirty(1)).isTrue(); verify(helper).markFileDirty(eq(1)); }
|
### Question:
BreakpointStoreOnSQLite implements DownloadStore { @Override public boolean markFileClear(int id) { if (onCache.markFileClear(id)) { helper.markFileClear(id); return true; } return false; } BreakpointStoreOnSQLite(BreakpointSQLiteHelper helper, BreakpointStoreOnCache onCache); BreakpointStoreOnSQLite(Context context); @Nullable @Override BreakpointInfo get(int id); @NonNull @Override BreakpointInfo createAndInsert(@NonNull DownloadTask task); @Override void onTaskStart(int id); @Override void onSyncToFilesystemSuccess(@NonNull BreakpointInfo info, int blockIndex,
long increaseLength); @Override boolean update(@NonNull BreakpointInfo breakpointInfo); @Override void onTaskEnd(int id, @NonNull EndCause cause, @Nullable Exception exception); @Nullable @Override BreakpointInfo getAfterCompleted(int id); @Override boolean markFileDirty(int id); @Override boolean markFileClear(int id); @Override void remove(int id); @Override int findOrCreateId(@NonNull DownloadTask task); @Nullable @Override BreakpointInfo findAnotherInfoFromCompare(@NonNull DownloadTask task,
@NonNull BreakpointInfo ignored); @Override boolean isOnlyMemoryCache(); @Override boolean isFileDirty(int id); @Nullable @Override String getResponseFilename(String url); @NonNull DownloadStore createRemitSelf(); }### Answer:
@Test public void markFileClear() { doReturn(false).when(onCache).markFileClear(1); assertThat(store.markFileClear(1)).isFalse(); verify(helper, never()).markFileClear(eq(1)); doReturn(true).when(onCache).markFileClear(1); assertThat(store.markFileClear(1)).isTrue(); verify(helper).markFileClear(eq(1)); }
|
### Question:
DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public void addHeader(String name, String value) { connection.addRequestProperty(name, value); } DownloadUrlConnection(URLConnection connection); DownloadUrlConnection(URLConnection connection, IRedirectHandler redirectHandler); DownloadUrlConnection(String originUrl, Configuration configuration); DownloadUrlConnection(URL url, Configuration configuration); DownloadUrlConnection(
URL url,
Configuration configuration,
IRedirectHandler redirectHandler); DownloadUrlConnection(String originUrl); @Override void addHeader(String name, String value); @Override Connected execute(); @Override int getResponseCode(); @Override InputStream getInputStream(); @Override boolean setRequestMethod(@NonNull String method); @Override Map<String, List<String>> getResponseHeaderFields(); @Override String getResponseHeaderField(String name); @Override String getRedirectLocation(); @Override void release(); @Override Map<String, List<String>> getRequestProperties(); @Override String getRequestProperty(String key); }### Answer:
@Test public void addHeader() throws Exception { downloadUrlConnection.addHeader("name1", "value1"); verify(urlConnection).addRequestProperty(eq("name1"), eq("value1")); }
|
### Question:
BreakpointStoreOnSQLite implements DownloadStore { @Override public boolean isFileDirty(int id) { return onCache.isFileDirty(id); } BreakpointStoreOnSQLite(BreakpointSQLiteHelper helper, BreakpointStoreOnCache onCache); BreakpointStoreOnSQLite(Context context); @Nullable @Override BreakpointInfo get(int id); @NonNull @Override BreakpointInfo createAndInsert(@NonNull DownloadTask task); @Override void onTaskStart(int id); @Override void onSyncToFilesystemSuccess(@NonNull BreakpointInfo info, int blockIndex,
long increaseLength); @Override boolean update(@NonNull BreakpointInfo breakpointInfo); @Override void onTaskEnd(int id, @NonNull EndCause cause, @Nullable Exception exception); @Nullable @Override BreakpointInfo getAfterCompleted(int id); @Override boolean markFileDirty(int id); @Override boolean markFileClear(int id); @Override void remove(int id); @Override int findOrCreateId(@NonNull DownloadTask task); @Nullable @Override BreakpointInfo findAnotherInfoFromCompare(@NonNull DownloadTask task,
@NonNull BreakpointInfo ignored); @Override boolean isOnlyMemoryCache(); @Override boolean isFileDirty(int id); @Nullable @Override String getResponseFilename(String url); @NonNull DownloadStore createRemitSelf(); }### Answer:
@Test public void isFileDirty() { doReturn(true).when(onCache).isFileDirty(1); assertThat(store.isFileDirty(1)).isTrue(); doReturn(false).when(onCache).isFileDirty(1); assertThat(store.isFileDirty(1)).isFalse(); }
|
### Question:
BlockInfoRow { public BlockInfo toInfo() { return new BlockInfo(startOffset, contentLength, currentOffset); } BlockInfoRow(Cursor cursor); int getBreakpointId(); long getStartOffset(); long getContentLength(); long getCurrentOffset(); BlockInfo toInfo(); }### Answer:
@Test public void toInfo() { final BlockInfo info = blockInfoRow.toInfo(); assertThat(info.getStartOffset()).isEqualTo(20); assertThat(info.getContentLength()).isEqualTo(30); assertThat(info.getCurrentOffset()).isEqualTo(5); }
|
### Question:
BreakpointSQLiteHelper extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (oldVersion == 1 && newVersion == 2) { db.execSQL("CREATE TABLE IF NOT EXISTS " + RESPONSE_FILENAME_TABLE_NAME + "( " + URL + " VARCHAR NOT NULL PRIMARY KEY, " + FILENAME + " VARCHAR NOT NULL)" ); } if (oldVersion <= 2) { db.execSQL("CREATE TABLE IF NOT EXISTS " + TASK_FILE_DIRTY_TABLE_NAME + "( " + ID + " INTEGER PRIMARY KEY)"); } } BreakpointSQLiteHelper(Context context); @Override void onOpen(SQLiteDatabase db); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); @Override void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion); void markFileDirty(int id); void markFileClear(int id); List<Integer> loadDirtyFileList(); SparseArray<BreakpointInfo> loadToCache(); HashMap<String, String> loadResponseFilenameToMap(); void updateFilename(@NonNull String url, @NonNull String filename); void insert(@NonNull BreakpointInfo info); void updateBlockIncrease(@NonNull BreakpointInfo info, int blockIndex,
long newCurrentOffset); void updateInfo(@NonNull BreakpointInfo info); void removeInfo(int id); void removeBlock(int breakpointId); }### Answer:
@Test public void onUpgrade() { helper.onUpgrade(db, 2, 3); verify(db).execSQL("CREATE TABLE IF NOT EXISTS " + TASK_FILE_DIRTY_TABLE_NAME + "( " + ID + " INTEGER PRIMARY KEY)"); }
|
### Question:
BreakpointSQLiteHelper extends SQLiteOpenHelper { public void markFileDirty(int id) { final SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(1); values.put(ID, id); db.insert(TASK_FILE_DIRTY_TABLE_NAME, null, values); } BreakpointSQLiteHelper(Context context); @Override void onOpen(SQLiteDatabase db); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); @Override void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion); void markFileDirty(int id); void markFileClear(int id); List<Integer> loadDirtyFileList(); SparseArray<BreakpointInfo> loadToCache(); HashMap<String, String> loadResponseFilenameToMap(); void updateFilename(@NonNull String url, @NonNull String filename); void insert(@NonNull BreakpointInfo info); void updateBlockIncrease(@NonNull BreakpointInfo info, int blockIndex,
long newCurrentOffset); void updateInfo(@NonNull BreakpointInfo info); void removeInfo(int id); void removeBlock(int breakpointId); }### Answer:
@Test public void markFileDirty() { doReturn(db).when(helper).getWritableDatabase(); helper.markFileDirty(1); ArgumentCaptor<ContentValues> captor = ArgumentCaptor.forClass(ContentValues.class); verify(db).insert(eq(TASK_FILE_DIRTY_TABLE_NAME), nullable(String.class), captor.capture()); assertThat(captor.getValue().get(ID)).isEqualTo(1); }
|
### Question:
BreakpointSQLiteHelper extends SQLiteOpenHelper { public void markFileClear(int id) { getWritableDatabase().delete(TASK_FILE_DIRTY_TABLE_NAME, ID + " = ?", new String[]{String.valueOf(id)}); } BreakpointSQLiteHelper(Context context); @Override void onOpen(SQLiteDatabase db); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); @Override void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion); void markFileDirty(int id); void markFileClear(int id); List<Integer> loadDirtyFileList(); SparseArray<BreakpointInfo> loadToCache(); HashMap<String, String> loadResponseFilenameToMap(); void updateFilename(@NonNull String url, @NonNull String filename); void insert(@NonNull BreakpointInfo info); void updateBlockIncrease(@NonNull BreakpointInfo info, int blockIndex,
long newCurrentOffset); void updateInfo(@NonNull BreakpointInfo info); void removeInfo(int id); void removeBlock(int breakpointId); }### Answer:
@Test public void markFileClear() { doReturn(db).when(helper).getWritableDatabase(); helper.markFileClear(1); ArgumentCaptor<String[]> captor = ArgumentCaptor.forClass(String[].class); verify(db).delete(eq(TASK_FILE_DIRTY_TABLE_NAME), eq(ID + " = ?"), captor.capture()); assertThat(captor.getValue()[0]).isEqualTo("1"); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.