TaskValidation extends Validation { public ValidationResult isNewNameValid(String name) { ValidationResult validationResult = isNameValid(name); if (validationResult.getValidationStatus() == ValidationStatus.INVALID) { return validationResult; } if (taskTemplateRepository.get(name).size() > 0) { 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 whenTaskNameToSaveIsValidExpectTaskIsValid() { when(taskTemplateRepository.get(VALID_TASK_NAME)).thenReturn(Collections.EMPTY_LIST); ValidationResult validationResult = taskValidation.isNewNameValid(VALID_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.VALID)); }
@Test public void whenTaskNameToSaveIsEmptyExpectTaskIsNotInvalid() { ValidationResult validationResult = taskValidation.isNewNameValid(EMPTY_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_EMPTY)); }
@Test public void whenTaskNameToSaveIsInvalidExpectTaskIsNotInvalid() { ValidationResult validationResult = taskValidation.isNewNameValid(INVALID_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_ONLY_LETTERS)); }
@Test public void whenTaskNameToSaveIsDuplicatedExpectTaskIsNotValid() { when(taskTemplateRepository.get(VALID_TASK_NAME)) .thenReturn(Collections.singletonList(duplicatedTaskTemplate)); ValidationResult validationResult = taskValidation.isNewNameValid(VALID_TASK_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_NAME_EXIST)); }