Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update VisibleForTesting annotations and naming of new repository #781

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update VisibleForTesting annotations and naming of new repository
  • Loading branch information
dazza5000 committed Feb 14, 2021
commit f610ae40ce5e9cff38deda593fd2f4ad22c205a3
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.example.android.architecture.blueprints.todoapp

import android.content.Context
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting.PRIVATE
import androidx.room.Room
import com.example.android.architecture.blueprints.todoapp.data.source.DefaultTasksRepository
import com.example.android.architecture.blueprints.todoapp.data.source.TasksDataSource
Expand All @@ -37,7 +38,7 @@ object ServiceLocator {
private var database: ToDoDatabase? = null
@Volatile
var tasksRepository: TasksRepository? = null
@VisibleForTesting set
@VisibleForTesting(otherwise = PRIVATE) set

fun provideTasksRepository(context: Context): TasksRepository {
synchronized(this) {
Expand All @@ -46,10 +47,10 @@ object ServiceLocator {
}

private fun createTasksRepository(context: Context): TasksRepository {
val newRepo =
val newTasksRepository =
DefaultTasksRepository(TasksRemoteDataSource, createTaskLocalDataSource(context))
tasksRepository = newRepo
return newRepo
tasksRepository = newTasksRepository
return newTasksRepository
}

private fun createTaskLocalDataSource(context: Context): TasksDataSource {
Expand All @@ -66,7 +67,7 @@ object ServiceLocator {
return result
}

@VisibleForTesting
@VisibleForTesting(otherwise = PRIVATE)
fun resetRepository() {
synchronized(lock) {
runBlocking {
Expand Down