### 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)); }