### Question:
AcceptCharsetHeaderDelegate implements HeaderDelegate<AcceptCharset> { public AcceptCharset fromString(String value) throws IllegalArgumentException { AcceptCharset cached = cache.get(value); if (cached != null) { return cached; } List<String> acceptable = new LinkedList<String>(); List<String> banned = new LinkedList<String>(); boolean anyAllowed = (value == null); List<AcceptCharset.ValuedCharset> vCharsets = parseAcceptCharset(value); for (AcceptCharset.ValuedCharset qCharset : vCharsets) { if (anyAllowed) { if (qCharset.qValue == 0 && !qCharset.isWildcard()) { banned.add(qCharset.charset); } } else { if (qCharset.qValue == 0) { break; } if (qCharset.isWildcard()) { anyAllowed = true; } else { acceptable.add(qCharset.charset); } } } return cache .put(value, new AcceptCharset(value, acceptable, banned, anyAllowed, vCharsets)); }  AcceptCharset fromString(String value); String toString(AcceptCharset value);  }### Answer:
@Test public void testFromStringNull() { AcceptCharset charset = acceptCharsetDelegate.fromString(null); assertTrue(charset.isAnyCharsetAllowed()); assertEquals(Collections.EMPTY_LIST, charset.getAcceptableCharsets()); assertEquals(Collections.EMPTY_LIST, charset.getBannedCharsets()); }
@Test public void testFromStringEmpty() { AcceptCharset charset = acceptCharsetDelegate.fromString(""); assertFalse(charset.isAnyCharsetAllowed()); assertEquals(Collections.singletonList("ISO-8859-1"), charset.getAcceptableCharsets()); assertEquals(Collections.EMPTY_LIST, charset.getBannedCharsets()); }
@Test public void testFromStringUTF8Only() { AcceptCharset charset = acceptCharsetDelegate.fromString("utf-8"); assertFalse(charset.isAnyCharsetAllowed()); assertEquals(Arrays.asList(new String[] {"ISO-8859-1", "utf-8"}), charset .getAcceptableCharsets()); assertEquals(Collections.EMPTY_LIST, charset.getBannedCharsets()); }
@Test public void testFromStringUTF8AndWildcard() { AcceptCharset charset = acceptCharsetDelegate.fromString("utf-8,*"); assertTrue(charset.isAnyCharsetAllowed()); assertEquals(Arrays.asList(new String[] {"utf-8"}), charset.getAcceptableCharsets()); assertEquals(Collections.EMPTY_LIST, charset.getBannedCharsets()); }
@Test public void testFromStringUTF8WithQuality() { AcceptCharset charset = acceptCharsetDelegate.fromString("utf-8;q=0.8"); assertFalse(charset.isAnyCharsetAllowed()); assertEquals(Arrays.asList(new String[] {"ISO-8859-1", "utf-8"}), charset .getAcceptableCharsets()); assertEquals(Arrays.asList(new AcceptCharset.ValuedCharset[] { new AcceptCharset.ValuedCharset(1.0, "ISO-8859-1"), new AcceptCharset.ValuedCharset(0.8, "utf-8")}), charset.getValuedCharsets()); assertEquals(Collections.EMPTY_LIST, charset.getBannedCharsets()); }
@Test public void testFromStringUTF8WithQualityAndWildcardWithQuality() { AcceptCharset charset = acceptCharsetDelegate.fromString("utf-8;q=0.8, *;q=0.4"); assertTrue(charset.isAnyCharsetAllowed()); assertEquals(Arrays.asList(new String[] {"utf-8"}), charset.getAcceptableCharsets()); assertEquals(Arrays.asList(new AcceptCharset.ValuedCharset[] { new AcceptCharset.ValuedCharset(0.8, "utf-8"), new AcceptCharset.ValuedCharset(0.4, null)}), charset.getValuedCharsets()); assertEquals(Collections.EMPTY_LIST, charset.getBannedCharsets()); }