CharacterConverter implements Converter<Character> { public Character convert(String value, Class<? extends Character> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } 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 shouldBeAbleToConvertCharacters() { assertThat(converter.convert("Z", Character.class, bundle), is(equalTo('Z'))); }
@Test public void shouldComplainAboutStringTooBig() { try { converter.convert("---", Character.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("--- is not a valid character."))); } }
@Test public void shouldNotComplainAboutNullAndEmpty() { assertThat(converter.convert(null, Character.class, bundle), is(nullValue())); assertThat(converter.convert("", Character.class, bundle), is(nullValue())); }