### Question:
Listener4Assist implements ListenerAssist { public void fetchProgress(DownloadTask task, int blockIndex, long increaseBytes) { final Listener4Model model = modelHandler.getOrRecoverModel(task, task.getInfo()); if (model == null) return; final long blockCurrentOffset = model.blockCurrentOffsetMap .get(blockIndex) + increaseBytes; model.blockCurrentOffsetMap.put(blockIndex, blockCurrentOffset); model.currentOffset += increaseBytes; if (assistExtend != null && assistExtend.dispatchFetchProgress(task, blockIndex, increaseBytes, model)) { return; } if (callback != null) { callback.progressBlock(task, blockIndex, blockCurrentOffset); callback.progress(task, model.currentOffset); } } Listener4Assist(ListenerModelHandler<T> handler);  Listener4Assist(ListenerModelHandler.ModelCreator<T> creator); void setCallback(@NonNull Listener4Callback callback); void setAssistExtend(@NonNull AssistExtend assistExtend); AssistExtend getAssistExtend(); void infoReady(DownloadTask task, BreakpointInfo info, boolean fromBreakpoint); void fetchProgress(DownloadTask task, int blockIndex, long increaseBytes); void fetchEnd(DownloadTask task, int blockIndex); synchronized void taskEnd(DownloadTask task, EndCause cause,
                                     @Nullable Exception realCause); @Override boolean isAlwaysRecoverAssistModel(); @Override void setAlwaysRecoverAssistModel(boolean isAlwaysRecoverAssistModel); @Override void setAlwaysRecoverAssistModelIfNotSet(boolean isAlwaysRecoverAssistModel);  }### Answer:
@Test public void fetchProgress_noModel() { when(handler.getOrRecoverModel(task, info)).thenReturn(null); assist.fetchProgress(task, 0, 0); verify(callback, never()).progress(eq(task), eq(0L)); verify(assistExtend, never()).dispatchFetchProgress(eq(task), eq(0), eq(0L), any(Listener4Assist.Listener4Model.class)); verify(handler).getOrRecoverModel(eq(task), eq(info)); }
@Test public void fetchProgress_dispatch() { when(handler.getOrRecoverModel(task, info)).thenReturn(model); final int blockIndex = 0; final long increaseBytes = 2L; when(assistExtend.dispatchFetchProgress(eq(task), eq(blockIndex), eq(increaseBytes), any(Listener4Assist.Listener4Model.class))) .thenReturn(true); assist.fetchProgress(task, blockIndex, increaseBytes); verify(callback, never()).progress(eq(task), anyLong()); verify(callback, never()).progressBlock(eq(task), eq(0), anyLong()); verify(handler).getOrRecoverModel(eq(task), eq(info)); }
@Test public void fetchProgress() { when(handler.getOrRecoverModel(task, info)).thenReturn(model); assist.fetchProgress(task, 0, 3); assertThat(model.getCurrentOffset()).isEqualTo(3); assertThat(model.getBlockCurrentOffsetMap().get(0)).isEqualTo(3); assertThat(model.getBlockCurrentOffsetMap().get(1)).isEqualTo(0); assertThat(model.getBlockCurrentOffsetMap().get(2)).isEqualTo(0); verify(callback).progressBlock(eq(task), eq(0), eq(3L)); verify(callback).progress(eq(task), eq(3L)); verify(handler).getOrRecoverModel(eq(task), eq(info)); assist.fetchProgress(task, 1, 2); assertThat(model.getCurrentOffset()).isEqualTo(5); assertThat(model.getBlockCurrentOffsetMap().get(1)).isEqualTo(2); verify(callback).progressBlock(eq(task), eq(1), eq(2L)); verify(callback).progress(eq(task), eq(5L)); }