@Test public final void shouldAddDefaultMessageIfValidationFailAndThereIsNoMessageAssignedToField() { stubFieldHookDef(false, Maps.<String, ErrorMessage> newHashMap()); boolean isValid = customValidator.call(entity, oldValue, newValue); assertFalse(isValid); verify(fieldHookDef, times(1)).call(entity, oldValue, newValue); ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class); verify(entity, times(1)).addError(Mockito.eq(fieldDefinition), argCaptor.capture(), Mockito.<String> anyVararg()); assertEquals(DEFAULT_MSG, argCaptor.getValue()); }
@Override public boolean call(final Entity entity, final Object oldValue, final Object newValue) { if (fieldHook.call(entity, oldValue, newValue)) { return true; } if (entity.getError(fieldDefinition.getName()) == null) { entity.addError(fieldDefinition, errorMessage); } return false; }
CustomValidator implements FieldHookDefinition, ErrorMessageDefinition { @Override public boolean call(final Entity entity, final Object oldValue, final Object newValue) { if (fieldHook.call(entity, oldValue, newValue)) { return true; } if (entity.getError(fieldDefinition.getName()) == null) { entity.addError(fieldDefinition, errorMessage); } return false; } }
CustomValidator implements FieldHookDefinition, ErrorMessageDefinition { @Override public boolean call(final Entity entity, final Object oldValue, final Object newValue) { if (fieldHook.call(entity, oldValue, newValue)) { return true; } if (entity.getError(fieldDefinition.getName()) == null) { entity.addError(fieldDefinition, errorMessage); } return false; } CustomValidator(final FieldHookDefinition fieldHook); }
CustomValidator implements FieldHookDefinition, ErrorMessageDefinition { @Override public boolean call(final Entity entity, final Object oldValue, final Object newValue) { if (fieldHook.call(entity, oldValue, newValue)) { return true; } if (entity.getError(fieldDefinition.getName()) == null) { entity.addError(fieldDefinition, errorMessage); } return false; } CustomValidator(final FieldHookDefinition fieldHook); @Override void initialize(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition); @Override boolean call(final Entity entity, final Object oldValue, final Object newValue); @Override void setErrorMessage(final String errorMessage); @Override int hashCode(); @Override boolean equals(final Object obj); }
CustomValidator implements FieldHookDefinition, ErrorMessageDefinition { @Override public boolean call(final Entity entity, final Object oldValue, final Object newValue) { if (fieldHook.call(entity, oldValue, newValue)) { return true; } if (entity.getError(fieldDefinition.getName()) == null) { entity.addError(fieldDefinition, errorMessage); } return false; } CustomValidator(final FieldHookDefinition fieldHook); @Override void initialize(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition); @Override boolean call(final Entity entity, final Object oldValue, final Object newValue); @Override void setErrorMessage(final String errorMessage); @Override int hashCode(); @Override boolean equals(final Object obj);  }