### Question:
MediaTypeHeaderProvider implements HeaderDelegate<MediaType> { public static MediaType valueOf(String mType) { if (mType == null) { throw new IllegalArgumentException("Media type value can not be null"); } MediaType result = map.get(mType); if (result == null) { result = internalValueOf(mType); final int size = map.size(); if (size >= MAX_MT_CACHE_SIZE) { map.clear(); } map.put(mType, result); } return result; }  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(expected = IllegalArgumentException.class) public void testNullValue() throws Exception { MediaType.valueOf(null); }
@Test public void testTypeWithExtendedParameters() { MediaType mt = MediaType.valueOf("multipart/related;type=application/dicom+xml"); assertEquals("multipart", mt.getType()); assertEquals("related", mt.getSubtype()); Map<String, String> params2 = mt.getParameters(); assertEquals(1, params2.size()); assertEquals("application/dicom+xml", params2.get("type")); }
@Test public void testTypeWithExtendedParametersQuote() { MediaType mt = MediaType.valueOf("multipart/related;type=\"application/dicom+xml\""); assertEquals("multipart", mt.getType()); assertEquals("related", mt.getSubtype()); Map<String, String> params2 = mt.getParameters(); assertEquals(1, params2.size()); assertEquals("\"application/dicom+xml\"", params2.get("type")); }
@Test public void testTypeWithExtendedAndBoundaryParameter() { MediaType mt = MediaType.valueOf( "multipart/related; type=application/dicom+xml; boundary=\"uuid:b9aecb2a-ab37-48d6-a1cd-b2f4f7fa63cb\""); assertEquals("multipart", mt.getType()); assertEquals("related", mt.getSubtype()); Map<String, String> params2 = mt.getParameters(); assertEquals(2, params2.size()); assertEquals("\"uuid:b9aecb2a-ab37-48d6-a1cd-b2f4f7fa63cb\"", params2.get("boundary")); assertEquals("application/dicom+xml", params2.get("type")); }
@Test public void testSimpleType() { MediaType m = MediaType.valueOf("text/html"); assertEquals("Media type was not parsed correctly", m, new MediaType("text", "html")); assertEquals("Media type was not parsed correctly", MediaType.valueOf("text/html "), new MediaType("text", "html")); }
@Test public void testShortWildcard() { MediaType m = MediaType.valueOf("*"); assertEquals("Media type was not parsed correctly", m, new MediaType("*", "*")); }
@Test public void testShortWildcardWithParameters() { MediaType m = MediaType.valueOf("*;q=0.2"); assertEquals("Media type was not parsed correctly", m, new MediaType("*", "*", Collections.singletonMap("q", "0.2"))); }
@Test public void testShortWildcardWithParameters2() { MediaType m = MediaType.valueOf("* ;q=0.2"); assertEquals("Media type was not parsed correctly", m, new MediaType("*", "*", Collections.singletonMap("q", "0.2"))); }
@Test public void testShortWildcardWithParameters3() { MediaType m = MediaType.valueOf("*; q=.2"); assertEquals("Media type was not parsed correctly", m, new MediaType("*", "*", Collections.singletonMap("q", ".2"))); }
@Test public void testTypeWithParameters() { MediaType mt = MediaType.valueOf("text/html;q=1234;b=4321"); assertEquals("text", mt.getType()); assertEquals("html", mt.getSubtype()); Map<String, String> params2 = mt.getParameters(); assertEquals(2, params2.size()); assertEquals("1234", params2.get("q")); assertEquals("4321", params2.get("b")); }