Skip to content

Commit abf5944

Browse files
author
David González
committed
Merge pull request android#16 from googlesamples/todo-mvp-loaders_fixRepoLocalCache
Adds unit test from todo-mvp
2 parents 92594ed + 939d15b commit abf5944

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

todoapp/app/src/test/java/com/example/android/architecture/blueprints/todoapp/data/source/TasksRepositoryTest.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616

1717
package com.example.android.architecture.blueprints.todoapp.data.source;
1818

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+
1930
import android.content.Context;
2031

2132
import com.example.android.architecture.blueprints.todoapp.data.Task;
@@ -31,15 +42,6 @@
3142

3243
import java.util.List;
3344

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-
4345
/**
4446
* Unit tests for the implementation of the in-memory repository with cache.
4547
*/
@@ -308,6 +310,21 @@ public void getTaskWithBothDataSourcesUnavailable_firesOnDataUnavailable() {
308310
assertThat(task, is(nullValue()));
309311
}
310312

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+
311328
/**
312329
* Convenience method that issues two calls to the tasks repository
313330
*/

todoapp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
jcenter()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
6+
classpath 'com.android.tools.build:gradle:2.1.0-alpha4'
77

88
// NOTE: Do not place your application dependencies here; they belong
99
// in the individual module build.gradle files

0 commit comments

Comments
 (0)