ConfigurationProperty { public void setValue(String value) { String errorMessage = validate(value); if (!"".equals(errorMessage)) { throw new IllegalArgumentException("The value \"" + value + "\" did not pass validation: " + errorMessage); } this.value = value; } ConfigurationProperty(String name, String description, String defaultValue);  ConfigurationProperty(String name, String description, String defaultValue, ValidationCallback validationCallback); String getName(); String getDescription(); String validate(String newValueCandidate); void setValue(String value); String getValue();  }
@Test public void setValue_should_succeed_if_validation_passes() { new ConfigurationProperty("", "", "").setValue(""); new ConfigurationProperty("", "", "").setValue("foo"); }
@Test public void setValue_should_fail_if_validation_fails() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("The value \"foo\" did not pass validation: Not valid!"); new ConfigurationProperty("", "", "", new ValidationCallback() { @Override public String validate(String newValueCandidate) { return newValueCandidate.isEmpty() ? "" : "The value \"" + newValueCandidate + "\" did not pass validation: Not valid!"; } }).setValue("foo"); }