### Question:
AddEditTaskLogic { @Nonnull public static Next<AddEditTaskModel, AddEditTaskEffect> update( AddEditTaskModel model, AddEditTaskEvent event) { return event.map( taskDefinitionCompleted -> onTaskDefinitionCompleted(model, taskDefinitionCompleted), taskCreatedSuccessfully -> exitWithSuccess(), taskCreationFailed -> exitWithFailure(), taskUpdatedSuccessfully -> exitWithSuccess(), taskUpdateFailed -> exitWithFailure()); }  @Nonnull static Next<AddEditTaskModel, AddEditTaskEffect> update(
      AddEditTaskModel model, AddEditTaskEvent event);  }### Answer:
@Test public void completingTaskDefinitionWithEmptyTitleAndDescriptionDoesNotUpdateState() { AddEditTaskModel updatingATask = AddEditTaskModel.builder() .mode(AddEditTaskMode.update("123")) .details(TaskDetails.create("T1", "This is a task")) .build(); updateSpec .given(updatingATask) .when(taskDefinitionCompleted("", " ")) .then(assertThatNext(hasNoModel(), hasEffects(notifyEmptyTaskNotAllowed()))); }
@Test public void tasksCanBeUpdatedWithEmptyTitle() { TaskDetails details = TaskDetails.create("T1", "This is a task"); AddEditTaskModel updatingATask = AddEditTaskModel.builder().mode(AddEditTaskMode.update("123")).details(details).build(); TaskDetails updatedDetails = details.toBuilder().title("").description("Hello World").build(); updateSpec .given(updatingATask) .when(taskDefinitionCompleted(" ", "Hello World")) .then( assertThatNext( hasModel(updatingATask.withDetails(updatedDetails)), hasEffects(saveTask(Task.create("123", updatedDetails))))); }
@Test public void tasksCanBeUpdatedWithEmptyDescription() { TaskDetails details = TaskDetails.create("T1", "This is a task"); AddEditTaskModel updatingATask = AddEditTaskModel.builder().mode(AddEditTaskMode.update("123")).details(details).build(); TaskDetails updatedDetails = details.toBuilder().title("Hello Tasks!").description("").build(); updateSpec .given(updatingATask) .when(taskDefinitionCompleted("Hello Tasks!", "")) .then( assertThatNext( hasModel(updatingATask.withDetails(updatedDetails)), hasEffects(saveTask(Task.create("123", updatedDetails))))); }
@Test public void taskUpdateSuccessShouldExit() { AddEditTaskModel updatingATask = AddEditTaskModel.builder() .mode(AddEditTaskMode.update("1234")) .details(TaskDetails.create("hello", "world")) .build(); updateSpec .given(updatingATask) .when(taskUpdatedSuccessfully()) .then(assertThatNext(hasNoModel(), hasEffects(exit(true)))); }
@Test public void taskUpdateFailureShouldExit() { AddEditTaskModel updatingATask = AddEditTaskModel.builder() .mode(AddEditTaskMode.update("1234")) .details(TaskDetails.create("hello", "world")) .build(); updateSpec .given(updatingATask) .when(taskUpdateFailed("Database Unavailable")) .then(assertThatNext(hasNoModel(), hasEffects(exit(false)))); }