### Question:
ContentNegotiationUtils { static Weighted<CharacterEncoding> acceptCharset(final String header) { return Weighted.fromString(header, new CharsetParser()); } private  ContentNegotiationUtils();   }### Answer:
@Test public void acceptCharsetDoesNotAllowParametersAfterQualityDefinition() { try { acceptCharset("utf-8;q=0.000;param=value"); fail("acceptCharset should fail when parameters are found after quality definition"); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(),equalTo("Content after quality definition is not allowed (;param=value)")); } }
@Test public void testAcceptCharset$onlyAcceptsOneWeight() throws Exception { try { acceptCharset("utf-8;q=0.000;q=1.000"); fail("Should fail for a charset with multiple qualities"); } catch(final IllegalArgumentException e) { assertThat(e.getMessage(),startsWith("Only one quality value can be specified (found 2: ")); } }
@Test public void dependsOnCharacterEncodingsClassForCreatingWeightedCharacterEncodings() throws Exception { final Charset expected=StandardCharsets.UTF_8; new MockUp<CharacterEncodings>() { @Mock public CharacterEncoding fromString(Invocation context, String aValue) { assertThat(aValue,equalTo(expected.name())); return context.proceed(aValue); } }; final Weighted<CharacterEncoding> result=acceptCharset(expected.name()); assertThat(result,not(nullValue())); assertThat(result.entity().charset(),equalTo(expected)); assertThat(result.hasWeight(),equalTo(false)); assertThat(result.weight(),equalTo(1.0D)); }