PrimitiveCharConverter implements Converter<Character> { public Character convert(String value, Class<? extends Character> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return '\u0000'; } if (value.length() != 1) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_character"), value)); } return value.charAt(0); }  Character convert(String value, Class<? extends Character> type, ResourceBundle bundle);  }
@Test public void shouldBeAbleToConvertNumbers() { assertThat((Character) converter.convert("r", char.class, bundle), is(equalTo('r'))); }
@Test public void shouldComplainAboutInvalidNumber() { try { converter.convert("---", char.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("--- is not a valid character."))); } }
@Test public void shouldConvertToZeroWhenNull() { assertThat((Character) converter.convert(null, char.class, bundle), is(equalTo('\u0000'))); }
@Test public void shouldConvertToZeroWhenEmpty() { assertThat((Character) converter.convert("", char.class, bundle), is(equalTo('\u0000'))); }