CharsetConverter implements IStringConverter<Charset> { @Override public Charset convert(String parameterValue) { checkNotNull(parameterValue, "parameterValue is null"); try { return Charset.forName(parameterValue); } catch (UnsupportedCharsetException e) { throw new ParameterException("Unsupported character set: " + e.getMessage()); } catch (IllegalCharsetNameException e) { throw new ParameterException("Illegal character set name: " + e.getMessage()); } }  @Override Charset convert(String parameterValue);  }
@Test(expected = NullPointerException.class) public void givenValueIsNull_whenConvert_thenThrowsNullPointerException() { converter.convert(null); }
@Test(expected = ParameterException.class) public void givenValueIsEmpty_whenConvert_thenThrowsParameterException() { converter.convert(""); }
@Test public void givenValueIsUTF8_whenConvert_thenReturnsExpectedCharset() { Charset result = converter.convert("UTF8"); assertThat(result, equalTo(Charsets.UTF_8)); }
@Test(expected = ParameterException.class) public void givenValueIsInvalidCharset_whenConvert_thenThrowsParameterException() { converter.convert("NOT_A_CHARSET"); }