HeaderHelper { static float parseQualityValue(String qString) { if (qString.length() > 5) { throw new IllegalArgumentException("Quality value string has more then 5 characters"); } float qValue; try { qValue = Float.valueOf(qString); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid quality value '%s'", qString)); } if (qValue > 1.0F) { throw new IllegalArgumentException("Quality value can't be greater then 1.0"); } return qValue; } private  HeaderHelper(); static List<AcceptMediaType> createAcceptMediaTypeList(String header); static List<AcceptLanguage> createAcceptedLanguageList(String header); static List<AcceptToken> createAcceptedCharsetList(String header); static List<AcceptToken> createAcceptedEncodingList(String header); static List<Cookie> parseCookies(String cookiesString); static NewCookie parseNewCookie(String newCookieString); static Date parseDateHeader(String header); static String formatDate(Date date); static long getContentLengthLong(MultivaluedMap<String, String> httpHeaders); @SuppressWarnings({"unchecked"}) static String getHeaderAsString(Object o); static String convertToString(Collection<String> collection); static final Comparator<QualityValue> QUALITY_VALUE_COMPARATOR; }
@UseDataProvider("forParsesQualityValue") @Test public void parsesQualityValue(String qValueString, float expectedResult) throws Exception { assertEquals(expectedResult, HeaderHelper.parseQualityValue(qValueString), 0.0f); }
@Test public void failsParseQualityValueWhenStringIsLongerThanFiveCharacters() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Quality value string has more then 5 characters"); HeaderHelper.parseQualityValue("0.7777"); }
@Test public void failsParseQualityValueWhenValueIsGreaterThanOne() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Quality value can't be greater then 1.0"); HeaderHelper.parseQualityValue("1.05"); }
@Test public void failsParseQualityValueWhenValueIsNotNumeric() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Invalid quality value '0.5x'"); HeaderHelper.parseQualityValue("0.5x"); }