PrimitiveIntConverter implements Converter<Integer> { public Integer convert(String value, Class<? extends Integer> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return 0; } try { return Integer.parseInt(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((Integer) converter.convert("2", int.class, bundle), is(equalTo(2))); }
@Test public void shouldComplainAboutInvalidNumber() { try { converter.convert("---", int.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("--- is not a valid integer."))); } }
@Test public void shouldConvertToZeroWhenNull() { assertThat((Integer) converter.convert(null, int.class, bundle), is(equalTo(0))); }
@Test public void shouldConvertToZeroWhenEmpty() { assertThat((Integer) converter.convert("", int.class, bundle), is(equalTo(0))); }