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

Rename smurf named methods #942

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class AddEditTaskScreenTest {
.performClick()

// THEN - Verify that the repository saved the task
val tasks = repository.getTasks(true)
val tasks = repository.getAll(true)
assertEquals(1, tasks.size)
assertEquals("title", tasks[0].title)
assertEquals("description", tasks[0].description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class StatisticsScreenTest {
fun tasks_showsNonEmptyMessage() = runTest {
// Given some tasks
repository.apply {
createTask("Title1", "Description1")
createTask("Title2", "Description2").also {
completeTask(it)
create("Title1", "Description1")
create("Title2", "Description2").also {
complete(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class TaskDetailScreenTest {
@Test
fun activeTaskDetails_DisplayedInUi() = runTest {
// GIVEN - Add active (incomplete) task to the DB
val activeTaskId = repository.createTask(
val activeTaskId = repository.create(
title = "Active Task",
description = "AndroidX Rocks"
)
Expand All @@ -84,8 +84,8 @@ class TaskDetailScreenTest {
@Test
fun completedTaskDetails_DisplayedInUi() = runTest {
// GIVEN - Add completed task to the DB
val completedTaskId = repository.createTask("Completed Task", "AndroidX Rocks")
repository.completeTask(completedTaskId)
val completedTaskId = repository.create("Completed Task", "AndroidX Rocks")
repository.complete(completedTaskId)

// WHEN - Details screen is opened
setContent(completedTaskId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class AppNavigationTest {
@Test
fun taskDetailScreen_doubleUIBackButton() = runTest {
val taskName = "UI <- button"
taskRepository.createTask(taskName, "Description")
taskRepository.create(taskName, "Description")

setContent()

Expand Down Expand Up @@ -159,7 +159,7 @@ class AppNavigationTest {
@Test
fun taskDetailScreen_doubleBackButton() = runTest {
val taskName = "Back button"
taskRepository.createTask(taskName, "Description")
taskRepository.create(taskName, "Description")

setContent()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TasksScreenTest {
@Test
fun displayTask_whenRepositoryHasData() = runTest {
// GIVEN - One task already in the repository
repository.createTask("TITLE1", "DESCRIPTION1")
repository.create("TITLE1", "DESCRIPTION1")

// WHEN - On startup
setContent()
Expand All @@ -82,7 +82,7 @@ class TasksScreenTest {

@Test
fun displayActiveTask() = runTest {
repository.createTask("TITLE1", "DESCRIPTION1")
repository.create("TITLE1", "DESCRIPTION1")

setContent()

Expand All @@ -99,7 +99,7 @@ class TasksScreenTest {
@Test
fun displayCompletedTask() = runTest {
repository.apply {
createTask("TITLE1", "DESCRIPTION1").also { completeTask(it) }
create("TITLE1", "DESCRIPTION1").also { complete(it) }
}

setContent()
Expand All @@ -115,7 +115,7 @@ class TasksScreenTest {

@Test
fun markTaskAsComplete() = runTest {
repository.createTask("TITLE1", "DESCRIPTION1")
repository.create("TITLE1", "DESCRIPTION1")

setContent()

Expand All @@ -134,7 +134,7 @@ class TasksScreenTest {
@Test
fun markTaskAsActive() = runTest {
repository.apply {
createTask("TITLE1", "DESCRIPTION1").also { completeTask(it) }
create("TITLE1", "DESCRIPTION1").also { complete(it) }
}

setContent()
Expand All @@ -155,8 +155,8 @@ class TasksScreenTest {
fun showAllTasks() = runTest {
// Add one active task and one completed task
repository.apply {
createTask("TITLE1", "DESCRIPTION1")
createTask("TITLE2", "DESCRIPTION2").also { completeTask(it) }
create("TITLE1", "DESCRIPTION1")
create("TITLE2", "DESCRIPTION2").also { complete(it) }
}

setContent()
Expand All @@ -171,9 +171,9 @@ class TasksScreenTest {
fun showActiveTasks() = runTest {
// Add 2 active tasks and one completed task
repository.apply {
createTask("TITLE1", "DESCRIPTION1")
createTask("TITLE2", "DESCRIPTION2")
createTask("TITLE3", "DESCRIPTION3").also { completeTask(it) }
create("TITLE1", "DESCRIPTION1")
create("TITLE2", "DESCRIPTION2")
create("TITLE3", "DESCRIPTION3").also { complete(it) }
}

setContent()
Expand All @@ -189,9 +189,9 @@ class TasksScreenTest {
fun showCompletedTasks() = runTest {
// Add one active task and 2 completed tasks
repository.apply {
createTask("TITLE1", "DESCRIPTION1")
createTask("TITLE2", "DESCRIPTION2").also { completeTask(it) }
createTask("TITLE3", "DESCRIPTION3").also { completeTask(it) }
create("TITLE1", "DESCRIPTION1")
create("TITLE2", "DESCRIPTION2").also { complete(it) }
create("TITLE3", "DESCRIPTION3").also { complete(it) }
}

setContent()
Expand All @@ -207,8 +207,8 @@ class TasksScreenTest {
fun clearCompletedTasks() = runTest {
// Add one active task and one completed task
repository.apply {
createTask("TITLE1", "DESCRIPTION1")
createTask("TITLE2", "DESCRIPTION2").also { completeTask(it) }
create("TITLE1", "DESCRIPTION1")
create("TITLE2", "DESCRIPTION2").also { complete(it) }
}

setContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TasksTest {
@Test
fun editTask() = runTest {
val originalTaskTitle = "TITLE1"
repository.createTask(originalTaskTitle, "DESCRIPTION")
repository.create(originalTaskTitle, "DESCRIPTION")

setContent()

Expand Down Expand Up @@ -143,8 +143,8 @@ class TasksTest {
@Test
fun createTwoTasks_deleteOneTask() = runTest {
repository.apply {
createTask("TITLE1", "DESCRIPTION")
createTask("TITLE2", "DESCRIPTION")
create("TITLE1", "DESCRIPTION")
create("TITLE2", "DESCRIPTION")
}

setContent()
Expand All @@ -169,7 +169,7 @@ class TasksTest {
fun markTaskAsCompleteOnDetailScreen_taskIsCompleteInList() = runTest {
// Add 1 active task
val taskTitle = "COMPLETED"
repository.createTask(taskTitle, "DESCRIPTION")
repository.create(taskTitle, "DESCRIPTION")

setContent()

Expand All @@ -195,7 +195,7 @@ class TasksTest {
// Add 1 completed task
val taskTitle = "ACTIVE"
repository.apply {
createTask(taskTitle, "DESCRIPTION").also { completeTask(it) }
create(taskTitle, "DESCRIPTION").also { complete(it) }
}

setContent()
Expand All @@ -221,7 +221,7 @@ class TasksTest {
fun markTaskAsCompleteAndActiveOnDetailScreen_taskIsActiveInList() = runTest {
// Add 1 active task
val taskTitle = "ACT-COMP"
repository.createTask(taskTitle, "DESCRIPTION")
repository.create(taskTitle, "DESCRIPTION")

setContent()

Expand Down Expand Up @@ -249,7 +249,7 @@ class TasksTest {
// Add 1 completed task
val taskTitle = "COMP-ACT"
repository.apply {
createTask(taskTitle, "DESCRIPTION").also { completeTask(it) }
create(taskTitle, "DESCRIPTION").also { complete(it) }
}

setContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AddEditTaskViewModel @Inject constructor(
}

private fun createNewTask() = viewModelScope.launch {
taskRepository.createTask(uiState.value.title, uiState.value.description)
taskRepository.create(uiState.value.title, uiState.value.description)
_uiState.update {
it.copy(isTaskSaved = true)
}
Expand All @@ -111,7 +111,7 @@ class AddEditTaskViewModel @Inject constructor(
throw RuntimeException("updateTask() was called but task is new.")
}
viewModelScope.launch {
taskRepository.updateTask(
taskRepository.update(
taskId,
title = uiState.value.title,
description = uiState.value.description,
Expand All @@ -127,7 +127,7 @@ class AddEditTaskViewModel @Inject constructor(
it.copy(isLoading = true)
}
viewModelScope.launch {
taskRepository.getTask(taskId).let { task ->
taskRepository.get(taskId).let { task ->
if (task != null) {
_uiState.update {
it.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DefaultTaskRepository @Inject constructor(
@ApplicationScope private val scope: CoroutineScope,
) : TaskRepository {

override suspend fun createTask(title: String, description: String): String {
override suspend fun create(title: String, description: String): String {
// ID creation might be a complex operation so it's executed using the supplied
// coroutine dispatcher
val taskId = withContext(dispatcher) {
Expand All @@ -64,8 +64,8 @@ class DefaultTaskRepository @Inject constructor(
return taskId
}

override suspend fun updateTask(taskId: String, title: String, description: String) {
val task = getTask(taskId)?.copy(
override suspend fun update(taskId: String, title: String, description: String) {
val task = get(taskId)?.copy(
title = title,
description = description
) ?: throw Exception("Task (id $taskId) not found")
Expand All @@ -74,7 +74,7 @@ class DefaultTaskRepository @Inject constructor(
saveTasksToNetwork()
}

override suspend fun getTasks(forceUpdate: Boolean): List<Task> {
override suspend fun getAll(forceUpdate: Boolean): List<Task> {
if (forceUpdate) {
refresh()
}
Expand All @@ -83,19 +83,19 @@ class DefaultTaskRepository @Inject constructor(
}
}

override fun getTasksStream(): Flow<List<Task>> {
override fun observeAll(): Flow<List<Task>> {
return localDataSource.observeAll().map { tasks ->
withContext(dispatcher) {
tasks.toExternal()
}
}
}

override suspend fun refreshTask(taskId: String) {
override suspend fun refresh(taskId: String) {
refresh()
}

override fun getTaskStream(taskId: String): Flow<Task?> {
override fun observe(taskId: String): Flow<Task?> {
return localDataSource.observeById(taskId).map { it.toExternal() }
}

Expand All @@ -105,34 +105,34 @@ class DefaultTaskRepository @Inject constructor(
* @param taskId - The ID of the task
* @param forceUpdate - true if the task should be updated from the network data source first.
*/
override suspend fun getTask(taskId: String, forceUpdate: Boolean): Task? {
override suspend fun get(taskId: String, forceUpdate: Boolean): Task? {
if (forceUpdate) {
refresh()
}
return localDataSource.getById(taskId)?.toExternal()
}

override suspend fun completeTask(taskId: String) {
override suspend fun complete(taskId: String) {
localDataSource.updateCompleted(taskId = taskId, completed = true)
saveTasksToNetwork()
}

override suspend fun activateTask(taskId: String) {
override suspend fun activate(taskId: String) {
localDataSource.updateCompleted(taskId = taskId, completed = false)
saveTasksToNetwork()
}

override suspend fun clearCompletedTasks() {
override suspend fun clearAllCompleted() {
localDataSource.deleteCompleted()
saveTasksToNetwork()
}

override suspend fun deleteAllTasks() {
override suspend fun deleteAll() {
localDataSource.deleteAll()
saveTasksToNetwork()
}

override suspend fun deleteTask(taskId: String) {
override suspend fun delete(taskId: String) {
localDataSource.deleteById(taskId)
saveTasksToNetwork()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ import kotlinx.coroutines.flow.Flow
*/
interface TaskRepository {

fun getTasksStream(): Flow<List<Task>>
fun observeAll(): Flow<List<Task>>

suspend fun getTasks(forceUpdate: Boolean = false): List<Task>
suspend fun getAll(forceUpdate: Boolean = false): List<Task>

suspend fun refresh()

fun getTaskStream(taskId: String): Flow<Task?>
fun observe(taskId: String): Flow<Task?>

suspend fun getTask(taskId: String, forceUpdate: Boolean = false): Task?
suspend fun get(taskId: String, forceUpdate: Boolean = false): Task?

suspend fun refreshTask(taskId: String)
suspend fun refresh(taskId: String)

suspend fun createTask(title: String, description: String): String
suspend fun create(title: String, description: String): String

suspend fun updateTask(taskId: String, title: String, description: String)
suspend fun update(taskId: String, title: String, description: String)

suspend fun completeTask(taskId: String)
suspend fun complete(taskId: String)

suspend fun activateTask(taskId: String)
suspend fun activate(taskId: String)

suspend fun clearCompletedTasks()
suspend fun clearAllCompleted()

suspend fun deleteAllTasks()
suspend fun deleteAll()

suspend fun deleteTask(taskId: String)
suspend fun delete(taskId: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class StatisticsViewModel @Inject constructor(
) : ViewModel() {

val uiState: StateFlow<StatisticsUiState> =
taskRepository.getTasksStream()
taskRepository.observeAll()
.map { Async.Success(it) }
.catch<Async<List<Task>>> { emit(Async.Error(R.string.loading_tasks_error)) }
.map { taskAsync -> produceStatisticsUiState(taskAsync) }
Expand Down
Loading