TasksRepository implements TasksDataSource { @Override public void getTask(@NonNull final String taskId, @NonNull final GetTaskCallback callback) { checkNotNull(taskId); checkNotNull(callback); Task cachedTask = getTaskWithId(taskId); if (cachedTask != null) { callback.onTaskLoaded(cachedTask); return; } mTasksLocalDataSource.getTask(taskId, new GetTaskCallback() { @Override public void onTaskLoaded(Task task) { callback.onTaskLoaded(task); } @Override public void onDataNotAvailable() { mTasksRemoteDataSource.getTask(taskId, new GetTaskCallback() { @Override public void onTaskLoaded(Task task) { callback.onTaskLoaded(task); } @Override public void onDataNotAvailable() { callback.onDataNotAvailable(); } }); } }); } private  TasksRepository(@NonNull TasksDataSource tasksRemoteDataSource,
                            @NonNull TasksDataSource tasksLocalDataSource); static TasksRepository getInstance(TasksDataSource tasksRemoteDataSource,
                                              TasksDataSource tasksLocalDataSource); static void destroyInstance(); @Override void getTasks(@NonNull final LoadTasksCallback callback); @Override void saveTask(@NonNull Task task); @Override void completeTask(@NonNull Task task); @Override void completeTask(@NonNull String taskId); @Override void activateTask(@NonNull Task task); @Override void activateTask(@NonNull String taskId); @Override void clearCompletedTasks(); @Override void getTask(@NonNull final String taskId, @NonNull final GetTaskCallback callback); @Override void refreshTasks(); @Override void deleteAllTasks(); @Override void deleteTask(@NonNull String taskId);  }
@Test public void getTask_requestsSingleTaskFromLocalDataSource() { mTasksRepository.getTask(TASK_TITLE, mGetTaskCallback); verify(mTasksLocalDataSource).getTask(eq(TASK_TITLE), any( TasksDataSource.GetTaskCallback.class)); }
@Test public void getTaskWithBothDataSourcesUnavailable_firesOnDataUnavailable() { final String taskId = "123"; mTasksRepository.getTask(taskId, mGetTaskCallback); setTaskNotAvailable(mTasksLocalDataSource, taskId); setTaskNotAvailable(mTasksRemoteDataSource, taskId); verify(mGetTaskCallback).onDataNotAvailable(); }