CookieModifierValidator implements Validator { @Override public void validate(ValidationResultBuilder builder) { if (modifyAction == null) { builder.addErrorMessage("Provided modify action is null"); } else { switch (modifyAction) { case ADD: validateAddAction(builder); break; case REMOVE: validateRemoveAction(builder); break; default: break; } } } CookieModifierValidator(String name, String value, ModifyAction modifyAction); @Override void validate(ValidationResultBuilder builder);  }
@Test public void validate_addAction() { Validator tested = getTested(NAME, VALUE, ModifyAction.ADD); tested.validate(validationResultBuilder); verify(validationResultBuilder, noMoreInteractions()).addErrorMessage(anyString()); }
@Test public void validate_addActionNoName() { Validator tested = getTested(null, VALUE, ModifyAction.ADD); tested.validate(validationResultBuilder); verify(validationResultBuilder, times(1)).addErrorMessage(contains(VALIDATION_ERROR_ADD)); }
@Test public void validate_addActionNoValue() { Validator tested = getTested(null, VALUE, ModifyAction.ADD); tested.validate(validationResultBuilder); verify(validationResultBuilder, times(1)).addErrorMessage(contains(VALIDATION_ERROR_ADD)); }
@Test public void validate_addActionNoNameAndValue() { Validator tested = getTested(null, VALUE, ModifyAction.ADD); tested.validate(validationResultBuilder); verify(validationResultBuilder, times(1)).addErrorMessage(contains(VALIDATION_ERROR_ADD)); }
@Test public void validate_removeAction() { Validator tested = getTested(NAME, VALUE, ModifyAction.REMOVE); tested.validate(validationResultBuilder); verify(validationResultBuilder, noMoreInteractions()).addErrorMessage(anyString()); }
@Test public void validate_removeActionNoName() { Validator tested = getTested(null, VALUE, ModifyAction.REMOVE); tested.validate(validationResultBuilder); verify(validationResultBuilder, times(1)).addErrorMessage(contains(VALIDATION_ERROR_REMOVE)); }
@Test public void validate_noAction() { Validator tested = getTested(NAME, VALUE, null); tested.validate(validationResultBuilder); verify(validationResultBuilder, times(1)) .addErrorMessage(contains(VALIDATION_ERROR_NULL_MODIFY_ACTION)); }