|
16 | 16 |
|
17 | 17 | package com.example.android.architecture.blueprints.todoapp.data.source;
|
18 | 18 |
|
| 19 | +import static org.hamcrest.CoreMatchers.is; |
| 20 | +import static org.hamcrest.CoreMatchers.nullValue; |
| 21 | +import static org.junit.Assert.assertNull; |
| 22 | +import static org.junit.Assert.assertThat; |
| 23 | +import static org.junit.Assert.assertTrue; |
| 24 | +import static org.mockito.Matchers.any; |
| 25 | +import static org.mockito.Matchers.eq; |
| 26 | +import static org.mockito.Mockito.times; |
| 27 | +import static org.mockito.Mockito.verify; |
| 28 | +import static org.mockito.Mockito.when; |
| 29 | + |
19 | 30 | import android.content.Context;
|
20 | 31 |
|
21 | 32 | import com.example.android.architecture.blueprints.todoapp.data.Task;
|
|
31 | 42 |
|
32 | 43 | import java.util.List;
|
33 | 44 |
|
34 |
| -import static org.hamcrest.CoreMatchers.is; |
35 |
| -import static org.hamcrest.CoreMatchers.nullValue; |
36 |
| -import static org.junit.Assert.assertNull; |
37 |
| -import static org.junit.Assert.assertThat; |
38 |
| -import static org.junit.Assert.assertTrue; |
39 |
| -import static org.mockito.Matchers.eq; |
40 |
| -import static org.mockito.Mockito.verify; |
41 |
| -import static org.mockito.Mockito.when; |
42 |
| - |
43 | 45 | /**
|
44 | 46 | * Unit tests for the implementation of the in-memory repository with cache.
|
45 | 47 | */
|
@@ -308,6 +310,21 @@ public void getTaskWithBothDataSourcesUnavailable_firesOnDataUnavailable() {
|
308 | 310 | assertThat(task, is(nullValue()));
|
309 | 311 | }
|
310 | 312 |
|
| 313 | + @Test |
| 314 | + public void getTasks_refreshesLocalDataSource() { |
| 315 | + // Mark cache as dirty to force a reload of data from remote data source. |
| 316 | + mTasksRepository.refreshTasks(); |
| 317 | + |
| 318 | + // Make the remote data source return data |
| 319 | + setTasksAvailable(mTasksRemoteDataSource, TASKS); |
| 320 | + |
| 321 | + // When calling getTasks in the repository |
| 322 | + mTasksRepository.getTasks(); |
| 323 | + |
| 324 | + // Verify that the data fetched from the remote data source was saved in local. |
| 325 | + verify(mTasksLocalDataSource, times(TASKS.size())).saveTask(any(Task.class)); |
| 326 | + } |
| 327 | + |
311 | 328 | /**
|
312 | 329 | * Convenience method that issues two calls to the tasks repository
|
313 | 330 | */
|
|
0 commit comments