IntegerConverter implements Converter<Integer> { public Integer convert(String value, Class<? extends Integer> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { return Integer.valueOf(value); } catch (NumberFormatException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_integer"), value)); } }  Integer convert(String value, Class<? extends Integer> type, ResourceBundle bundle);  }
@Test public void shouldBeAbleToConvertNumbers() { assertThat(converter.convert("2", Integer.class, bundle), is(equalTo(2))); }
@Test public void shouldComplainAboutInvalidNumber() { try { converter.convert("---", Integer.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("--- is not a valid integer."))); } }
@Test public void shouldNotComplainAboutNull() { assertThat(converter.convert(null, Integer.class, bundle), is(nullValue())); }
@Test public void shouldNotComplainAboutEmpty() { assertThat(converter.convert("", Integer.class, bundle), is(nullValue())); }