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