@Test public void shouldThrowExceptionForInvalidString() { try { converter.convert("not a boolean!", Boolean.class, bundle); Assert.assertTrue(false); } catch(ConversionError e) { assertThat(e.getMessage(), is(equalTo("NOT A BOOLEAN! is not a valid boolean. Please use true/false, yes/no, y/n or on/off"))); } }
public Boolean convert(String value, Class<? extends Boolean> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } value = value.toUpperCase(); if (matches(IS_TRUE, value)) { return true; } else if (matches(IS_FALSE, value)) { return false; } throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_boolean"), value)); }
BooleanConverter implements Converter<Boolean> { public Boolean convert(String value, Class<? extends Boolean> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } value = value.toUpperCase(); if (matches(IS_TRUE, value)) { return true; } else if (matches(IS_FALSE, value)) { return false; } throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_boolean"), value)); } }
BooleanConverter implements Converter<Boolean> { public Boolean convert(String value, Class<? extends Boolean> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } value = value.toUpperCase(); if (matches(IS_TRUE, value)) { return true; } else if (matches(IS_FALSE, value)) { return false; } throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_boolean"), value)); }  }
BooleanConverter implements Converter<Boolean> { public Boolean convert(String value, Class<? extends Boolean> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } value = value.toUpperCase(); if (matches(IS_TRUE, value)) { return true; } else if (matches(IS_FALSE, value)) { return false; } throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_boolean"), value)); }  Boolean convert(String value, Class<? extends Boolean> type, ResourceBundle bundle); }
BooleanConverter implements Converter<Boolean> { public Boolean convert(String value, Class<? extends Boolean> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } value = value.toUpperCase(); if (matches(IS_TRUE, value)) { return true; } else if (matches(IS_FALSE, value)) { return false; } throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_boolean"), value)); }  Boolean convert(String value, Class<? extends Boolean> type, ResourceBundle bundle);  }