From 7382c96296ccf65ef2dfe3b58ac3a009bb7f15ba Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 13 Feb 2018 10:02:22 +0100 Subject: [PATCH 1/2] Update AddEditTaskPresenter.java --- .../todoapp/addedittask/AddEditTaskPresenter.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskPresenter.java b/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskPresenter.java index 689797a06..261ea2536 100644 --- a/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskPresenter.java +++ b/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskPresenter.java @@ -150,7 +150,13 @@ private void updateTask(String title, String description) { if (isNewTask()) { throw new RuntimeException("updateTask() was called but task is new."); } - mTasksRepository.saveTask(new Task(title, description, mTaskId)); - mAddTaskView.showTasksList(); // After an edit, go back to the list. + + Task newTask = new Task(title, description, mTaskId); + if (newTask.isEmpty()) { + mAddTaskView.showEmptyTaskError(); + } else { + mTasksRepository.saveTask(newTask); + mAddTaskView.showTasksList(); // After an edit, go back to the list. + } } } From d5cc0764e769e70d2e69432028478216730492a5 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 13 Feb 2018 10:04:45 +0100 Subject: [PATCH 2/2] added test to cover empty edit scenario --- .../addedittask/AddEditTaskPresenterTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/todoapp/app/src/test/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskPresenterTest.java b/todoapp/app/src/test/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskPresenterTest.java index c3314aa00..96adaead1 100644 --- a/todoapp/app/src/test/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskPresenterTest.java +++ b/todoapp/app/src/test/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskPresenterTest.java @@ -101,6 +101,19 @@ public void saveTask_emptyTaskShowsErrorUi() { verify(mAddEditTaskView).showEmptyTaskError(); } + @Test + public void saveExistingTaskWithEmptyNameToRepository_emptyTaskShowsErrorUi() { + // Get a reference to the class under test + mAddEditTaskPresenter = new AddEditTaskPresenter( + "1", mTasksRepository, mAddEditTaskView, true, mSchedulerProvider); + + // When the presenter is asked to save an empty task + mAddEditTaskPresenter.saveTask("", ""); + + // Then an empty not error is shown in the UI + verify(mAddEditTaskView).showEmptyTaskError(); + } + @Test public void saveExistingTaskToRepository_showsSuccessMessageUi() { // Get a reference to the class under test