AcceptToken implements QualityValue { public static AcceptToken valueOf(String value) { if (value == null) { throw new IllegalArgumentException(); } try { int separator = scan(value, PARAMETERS_SEPARATOR); boolean hasParameters = charAtIs(value, separator, PARAMETERS_SEPARATOR); String token = hasParameters ? value.substring(0, separator).trim() : value.trim(); token = token.trim(); int i; if ((i = isToken(token)) != -1) { throw new IllegalArgumentException(String.format("Not valid character at index %d in %s", i, token)); } if (hasParameters) { Map<String, String> param = new HeaderParameterParser().parse(value); if (param.containsKey(QVALUE)) { return new AcceptToken(token, parseQualityValue(param.get(QVALUE))); } } return new AcceptToken(token); } catch (ParseException e) { throw new IllegalArgumentException(e); } } AcceptToken(String token);  AcceptToken(String token, float qValue); static AcceptToken valueOf(String value); Token getToken(); @Override float getQvalue(); boolean isCompatible(AcceptToken other); boolean isCompatible(Token other); boolean isCompatible(String other); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@UseDataProvider("forTestValueOf") @Test public void testValueOf(String header, AcceptToken expectedResult) { assertEquals(expectedResult, AcceptToken.valueOf(header)); }
@Test(expected = IllegalArgumentException.class) public void throwExceptionWhenAcceptTokenHeaderIsNull() { AcceptToken.valueOf(null); }
@Test(expected = IllegalArgumentException.class) public void throwExceptionWhenAcceptTokenHeaderContainsInvalidCharacters() { AcceptToken.valueOf("utf[8"); }
@Test(expected = IllegalArgumentException.class) public void throwExceptionWhenAcceptTokenHeaderContainsNonUS_ASCIICharacters() { AcceptToken.valueOf("\u041f\u0440\u0438\u0432\u0456\u0442"); }