Skip to content

Commit d242832

Browse files
committed
Adds idling resources that were removed in a merge
1 parent 3fe9d28 commit d242832

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/source/DefaultTasksRepository.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.lifecycle.LiveData
1919
import com.example.android.architecture.blueprints.todoapp.data.Result
2020
import com.example.android.architecture.blueprints.todoapp.data.Result.Success
2121
import com.example.android.architecture.blueprints.todoapp.data.Task
22+
import com.example.android.architecture.blueprints.todoapp.util.wrapEspressoIdlingResource
2223
import kotlinx.coroutines.CoroutineDispatcher
2324
import kotlinx.coroutines.Dispatchers
2425
import kotlinx.coroutines.coroutineScope
@@ -35,14 +36,18 @@ class DefaultTasksRepository(
3536
) : TasksRepository {
3637

3738
override suspend fun getTasks(forceUpdate: Boolean): Result<List<Task>> {
38-
if (forceUpdate) {
39-
try {
40-
updateTasksFromRemoteDataSource()
41-
} catch (ex: Exception) {
42-
return Result.Error(ex)
39+
// Set app as busy while this function executes.
40+
wrapEspressoIdlingResource {
41+
42+
if (forceUpdate) {
43+
try {
44+
updateTasksFromRemoteDataSource()
45+
} catch (ex: Exception) {
46+
return Result.Error(ex)
47+
}
4348
}
49+
return tasksLocalDataSource.getTasks()
4450
}
45-
return tasksLocalDataSource.getTasks()
4651
}
4752

4853
override suspend fun refreshTasks() {
@@ -87,10 +92,13 @@ class DefaultTasksRepository(
8792
* Relies on [getTasks] to fetch data and picks the task with the same ID.
8893
*/
8994
override suspend fun getTask(taskId: String, forceUpdate: Boolean): Result<Task> {
90-
if (forceUpdate) {
91-
updateTaskFromRemoteDataSource(taskId)
95+
// Set app as busy while this function executes.
96+
wrapEspressoIdlingResource {
97+
if (forceUpdate) {
98+
updateTaskFromRemoteDataSource(taskId)
99+
}
100+
return tasksLocalDataSource.getTask(taskId)
92101
}
93-
return tasksLocalDataSource.getTask(taskId)
94102
}
95103

96104
override suspend fun saveTask(task: Task) {

app/src/main/java/com/example/android/architecture/blueprints/todoapp/statistics/StatisticsViewModel.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import com.example.android.architecture.blueprints.todoapp.data.Result.Error
2626
import com.example.android.architecture.blueprints.todoapp.data.Result.Success
2727
import com.example.android.architecture.blueprints.todoapp.data.Task
2828
import com.example.android.architecture.blueprints.todoapp.data.source.TasksRepository
29-
import com.example.android.architecture.blueprints.todoapp.util.wrapEspressoIdlingResource
3029
import kotlinx.coroutines.launch
3130

3231
/**
@@ -55,11 +54,9 @@ class StatisticsViewModel(
5554

5655
fun refresh() {
5756
_dataLoading.value = true
58-
wrapEspressoIdlingResource {
59-
viewModelScope.launch {
60-
tasksRepository.refreshTasks()
61-
_dataLoading.value = false
62-
}
57+
viewModelScope.launch {
58+
tasksRepository.refreshTasks()
59+
_dataLoading.value = false
6360
}
6461
}
6562
}

app/src/sharedTest/java/com/example/android/architecture/blueprints/todoapp/statistics/StatisticsFragmentTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class StatisticsFragmentTest {
9797
.getString(R.string.statistics_active_tasks, 50.0f)
9898
val expectedCompletedTaskText = getApplicationContext<Context>()
9999
.getString(R.string.statistics_completed_tasks, 50.0f)
100-
Thread.sleep(4000)
100+
101101
// check that both info boxes are displayed and contain the correct info
102102
onView(withId(R.id.stats_active_text)).check(matches(isDisplayed()))
103103
onView(withId(R.id.stats_active_text)).check(matches(withText(expectedActiveTaskText)))

0 commit comments

Comments
 (0)