TaskValidation extends Validation { public ValidationResult isUpdateNameValid(Long taskId, String name) { ValidationResult validationResult = isNameValid(name); if (validationResult.getValidationStatus() == ValidationStatus.INVALID) { return validationResult; } if (!checkUpdateNameDoesNotExist(taskId, name)) { return new ValidationResult(ValidationStatus.INVALID, stringProvider.getString(R.string.name_exist_msg)); } return new ValidationResult(ValidationStatus.VALID); } TaskValidation(StringsProvider stringsProvider,
            TaskTemplateRepository taskTemplateRepository); ValidationResult isNewNameValid(String name); ValidationResult isUpdateNameValid(Long taskId, String name); ValidationResult isDurationValid(String duration);  }
@Test public void whenTaskNameToUpdateIsValidExpectTaskIsValid() { when(taskTemplateRepository.get(VALID_TASK_NAME)).thenReturn(Collections.EMPTY_LIST); ValidationResult validationResult = taskValidation .isUpdateNameValid(TASK_ID, VALID_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.VALID)); }
@Test public void whenTaskNameToUpdateIsEmptyExpectTaskIsNotValid() { ValidationResult validationResult = taskValidation .isUpdateNameValid(TASK_ID, EMPTY_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_EMPTY)); }
@Test public void whenTaskNameToUpdateIsInvalidExpectTaskIsNotValid() { ValidationResult validationResult = taskValidation .isUpdateNameValid(TASK_ID, INVALID_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_ONLY_LETTERS)); }
@Test public void whenTaskNameToUpdateIsDuplicatedExpectTaskIsNotValid() { when(taskTemplateRepository.get(VALID_TASK_NAME)).thenReturn(Collections.singletonList( duplicatedTaskTemplate)); ValidationResult validationResult = taskValidation .isUpdateNameValid(TASK_ID, VALID_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_NAME_EXIST)); }
@Test public void whenTaskNameToUpdateIsNotDuplicatedExpectTaskIsValid() { duplicatedTaskTemplate.setId(TASK_ID); when(taskTemplateRepository.get(VALID_TASK_NAME)).thenReturn(Collections.singletonList( duplicatedTaskTemplate)); ValidationResult validationResult = taskValidation .isUpdateNameValid(TASK_ID, VALID_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.VALID)); }