HeaderHelper { public static List<AcceptLanguage> createAcceptedLanguageList(String header) { if (isNullOrEmpty(header) || "*".equals(header)) { return ACCEPT_ALL_LANGUAGE; } return LIST_LANGUAGE_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 createsAcceptedLanguageListWhenHeaderIsNull() throws Exception { List<AcceptLanguage> acceptedLanguageList = HeaderHelper.createAcceptedLanguageList(null); assertEquals(newArrayList(new AcceptLanguage(new Locale("*"))), acceptedLanguageList); }
@Test public void createsAcceptedLanguageListWhenHeaderIsEmptyString() throws Exception { List<AcceptLanguage> acceptedLanguageList = HeaderHelper.createAcceptedLanguageList(""); assertEquals(newArrayList(new AcceptLanguage(new Locale("*"))), acceptedLanguageList); }
@Test public void createsAcceptedLanguageListFromHeader() throws Exception { String languages = "da;q=0.825, en-GB, en;q=0.8"; List<AcceptLanguage> expectedAcceptedLanguageList = newArrayList(new AcceptLanguage(new Locale("en", "GB")), new AcceptLanguage(new Locale("da"), 0.825f), new AcceptLanguage(new Locale("en"), 0.8f)); List<AcceptLanguage> acceptedLanguageList = HeaderHelper.createAcceptedLanguageList(languages); assertEquals(expectedAcceptedLanguageList, acceptedLanguageList); }