### Question:
CharacterEncodings { public static CharacterEncoding fromString(final String name) { requireNonNull(name,"Character encoding name cannot be null"); try { if(WILDCARD.equals(name)) { return wildcard(); } else { return of(Charset.forName(name)); } } catch (final UnsupportedCharsetException ex) { throw new IllegalArgumentException("Unsupported character encoding '"+ex.getCharsetName()+"'",ex); } catch (final IllegalCharsetNameException ex) { throw new IllegalArgumentException("Invalid character encoding name '"+ex.getCharsetName()+"'",ex); } } private  CharacterEncodings(); static CharacterEncoding wildcard(); static CharacterEncoding of(Charset charset); static CharacterEncoding fromString(final String name); static boolean includes(CharacterEncoding ce1, CharacterEncoding ce2);  }### Answer:
@Test public void parsesWildcardCharacterEncodings() throws Exception { CharacterEncoding result = CharacterEncodings.fromString("*"); assertThat(result,notNullValue()); assertThat(result.isWildcard(),equalTo(true)); }
@Test public void parsesValidCharacterEncodings() throws Exception { Charset expected = StandardCharsets.US_ASCII; CharacterEncoding result = CharacterEncodings.fromString(expected.name()); assertThat(result,notNullValue()); assertThat(result.charset(),equalTo(expected)); }
@Test public void cannotParsesUnknownCharsets() throws Exception { try { CharacterEncodings.fromString("cateporra"); fail("Should not parse unknown charsets"); } catch (IllegalArgumentException e) { assertThat(e.getCause(),instanceOf(UnsupportedCharsetException.class)); } }
@Test public void cannotParseInvalidCharsetNames() throws Exception { try { CharacterEncodings.fromString("<UTF-8>"); fail("Should not parse invalid charset names"); } catch (IllegalArgumentException e) { assertThat(e.getCause(),instanceOf(IllegalCharsetNameException.class)); } }