### Question:
BreakpointStoreOnCache implements DownloadStore { @Override public synchronized int findOrCreateId(@NonNull DownloadTask task) { final Integer candidate = keyToIdMap.get(task); if (candidate != null) return candidate; final int size = storedInfos.size(); for (int i = 0; i < size; i++) { final BreakpointInfo info = storedInfos.valueAt(i); if (info != null && info.isSameFrom(task)) { return info.id; } } final int unStoredSize = unStoredTasks.size(); for (int i = 0; i < unStoredSize; i++) { final IdentifiedTask another = unStoredTasks.valueAt(i); if (another == null) continue; if (another.compareIgnoreId(task)) return another.getId(); } final int id = allocateId(); unStoredTasks.put(id, task.mock(id)); keyToIdMap.add(task, id); return id; } BreakpointStoreOnCache();   BreakpointStoreOnCache(SparseArray<BreakpointInfo> storedInfos,
                           List<Integer> fileDirtyList,
                           HashMap<String, String> responseFilenameMap,
                           SparseArray<IdentifiedTask> unStoredTasks,
                           List<Integer> sortedOccupiedIds,
                           KeyToIdMap keyToIdMap);  BreakpointStoreOnCache(SparseArray<BreakpointInfo> storedInfos,
                                  List<Integer> fileDirtyList,
                                  HashMap<String, String> responseFilenameMap); @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 synchronized void remove(int id); @Override synchronized int findOrCreateId(@NonNull DownloadTask task); @Override BreakpointInfo findAnotherInfoFromCompare(@NonNull DownloadTask task,
                                                     @NonNull BreakpointInfo ignored); @Override boolean isOnlyMemoryCache(); @Override boolean isFileDirty(int id); @Nullable @Override String getResponseFilename(String url); static final int FIRST_ID; }### Answer:
@Test public void findOrCreateId() { final BreakpointStoreOnCache cache = spy(new BreakpointStoreOnCache( storedInfos, new ArrayList<Integer>(), new HashMap<String, String>(), unStoredTasks, sortedOccupiedIds, keyToIdMap)); when(keyToIdMap.get(task)).thenReturn(null); when(cache.allocateId()).thenReturn(1); assertThat(cache.findOrCreateId(task)).isEqualTo(1); verify(keyToIdMap).add(eq(task), eq(1)); when(keyToIdMap.get(task)).thenReturn(2); assertThat(cache.findOrCreateId(task)).isEqualTo(2); verify(keyToIdMap, never()).add(eq(task), eq(2)); }