HeaderHelper { public static List<AcceptMediaType> createAcceptMediaTypeList(String header) { if (isNullOrEmpty(header) || WILDCARD.equals(header.trim())) { return ACCEPT_ALL_MEDIA_TYPE; } return LIST_MEDIA_TYPE_PRODUCER.createQualitySortedList(header); } 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; }
@Test public void createsAcceptMediaTypeListWhenHeaderIsNull() { List<AcceptMediaType> acceptMediaTypeList = HeaderHelper.createAcceptMediaTypeList(null); List<AcceptMediaType> expectedAcceptMediaTypeList = newArrayList(new AcceptMediaType("*", "*")); assertEquals(expectedAcceptMediaTypeList, acceptMediaTypeList); }
@Test public void createsAcceptMediaTypeListWhenHeaderIsEmptyString() { List<AcceptMediaType> acceptMediaTypeList = HeaderHelper.createAcceptMediaTypeList(""); List<AcceptMediaType> expectedAcceptMediaTypeList = newArrayList(new AcceptMediaType("*", "*")); assertEquals(expectedAcceptMediaTypeList, acceptMediaTypeList); }
@Test public void createsAcceptMediaTypeListFromHeader() { String header = "text/xml; charset=utf8;q=0.825, text/html;charset=utf8, text/plain;charset=utf8;q=0.8"; List<AcceptMediaType> acceptMediaTypeList = HeaderHelper.createAcceptMediaTypeList(header); List<AcceptMediaType> expectedAcceptMediaTypeList = newArrayList( new AcceptMediaType("text", "html", ImmutableMap.of("charset", "utf8")), new AcceptMediaType("text", "xml", ImmutableMap.of("charset", "utf8", "q", "0.825")), new AcceptMediaType("text", "plain", ImmutableMap.of("charset", "utf8", "q", "0.8"))); assertEquals(expectedAcceptMediaTypeList, acceptMediaTypeList); }