PrimitiveLongConverter implements Converter<Long> { public Long convert(String value, Class<? extends Long> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return 0L; } try { return Long.parseLong(value); } catch (NumberFormatException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_integer"), value)); } }  Long convert(String value, Class<? extends Long> type, ResourceBundle bundle);  }
@Test public void shouldBeAbleToConvertNumbers() { assertThat((Long) converter.convert("2", long.class, bundle), is(equalTo(2L))); }
@Test public void shouldComplainAboutInvalidNumber() { try { converter.convert("---", long.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("--- is not a valid integer."))); } }
@Test public void shouldConvertToZeroWhenNull() { assertThat((Long) converter.convert(null, long.class, bundle), is(equalTo(0L))); }
@Test public void shouldConvertToZeroWhenEmpty() { assertThat((Long) converter.convert("", long.class, bundle), is(equalTo(0L))); }