### Question:
MediaTypeHeaderProvider implements HeaderDelegate<MediaType> { public MediaType fromString(String mType) { return valueOf(mType); }  MediaType fromString(String mType); static MediaType valueOf(String mType); static MediaType internalValueOf(String mType); String toString(MediaType type); static String typeToString(MediaType type); static String typeToString(MediaType type, List<String> ignoreParams);  }### Answer:
@Test public void testBadType() { try { new MediaTypeHeaderProvider().fromString("texthtml"); fail("Parse exception must've been thrown"); } catch (IllegalArgumentException pe) { } }
@Test public void testBadParameter() { try { new MediaTypeHeaderProvider().fromString("text/html;*"); fail("Parse exception must've been thrown"); } catch (IllegalArgumentException pe) { } }
@Test public void testIlleageMediaType() { try { new MediaTypeHeaderProvider().fromString("t fail("Parse exception expected"); } catch (IllegalArgumentException pe) { } try { new MediaTypeHeaderProvider().fromString("s fail("Parse exception expected"); } catch (IllegalArgumentException pe) { } try { new MediaTypeHeaderProvider().fromString("s/b/t;type=a/b"); fail("Parse exception expected"); } catch (IllegalArgumentException pe) { } try { new MediaTypeHeaderProvider().fromString("/b;type=a/b"); fail("Parse exception expected"); } catch (IllegalArgumentException pe) { } }
@Test public void testHeaderFileName() { String fileName = "version_2006&#65288;3&#65289;.pdf"; String header = "application/octet-stream; name=\"%s\""; String value = String.format(header, fileName); MediaTypeHeaderProvider provider = new MediaTypeHeaderProvider(); MediaType mt = provider.fromString(value); assertEquals("application", mt.getType()); assertEquals("octet-stream", mt.getSubtype()); Map<String, String> params = mt.getParameters(); assertEquals(1, params.size()); assertEquals("\"version_2006&#65288;3&#65289;.pdf\"", params.get("name")); }