PlanValidation extends Validation { public ValidationResult isNewNameValid(String name) { ValidationResult validationResult = isNameValid(name); if (validationResult.getValidationStatus() == ValidationStatus.INVALID) { return validationResult; } if (planTemplateRepository.get(name).size() > 0 ){ return new ValidationResult(ValidationStatus.INVALID, stringProvider.getString(R.string.name_exist_msg)); } return new ValidationResult(ValidationStatus.VALID); } PlanValidation(StringsProvider stringsProvider,
                          PlanTemplateRepository planTemplateRepository); ValidationResult isNewNameValid(String name); ValidationResult isUpdateNameValid(Long planId, String name);  }
@Test public void whenPlanNameIsValidExpectNewNameValidationPasses() { when(planTemplateRepository.get(VALID_PLAN_NAME)).thenReturn(Collections.EMPTY_LIST); ValidationResult validationResult = planValidation.isNewNameValid(VALID_PLAN_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.VALID)); }
@Test public void whenPlanNameIsEmptyExpectNewNameValidationFails() { ValidationResult validationResult = planValidation.isNewNameValid(EMPTY_PLAN_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_EMPTY)); }
@Test public void whenPlanNameIsInvalidExpectNewNameValidationFails() { ValidationResult validationResult = planValidation.isNewNameValid(INVALID_PLAN_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_ONLY_LETTERS)); }
@Test public void whenPlanNameIsDuplicatedExpectNewNameValidationFails() { when(planTemplateRepository.get(VALID_PLAN_NAME)) .thenReturn(Collections.singletonList(duplicatedPlanTemplate)); ValidationResult validationResult = planValidation.isNewNameValid(VALID_PLAN_NAME); assertThat(validationResult.getValidationStatus(), is(ValidationStatus.INVALID)); assertThat(validationResult.getValidationInfo(), is(ERROR_MESSAGE_NAME_EXIST)); }