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