### Question:
AcceptHeader { public String select(Iterable<String> supported) { float bestQ = 0; String best = null; for (String s : supported) { Atom a = match(s); if (a!= null && a.q > bestQ) { bestQ = a.q; best = s; } } if (best==null) throw HttpResponses.error(HttpServletResponse.SC_NOT_ACCEPTABLE, "Requested MIME types '" + ranges + "' didn't match any of the available options "+supported); return best; } AcceptHeader(String ranges); String select(Iterable<String> supported); String select(String... supported); @Override String toString();  }### Answer:
@Test public void qualityFactor4(){ String type = new AcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,**;q=0.8").select("foo/bar"); Assert.assertNotNull(type); Assert.assertEquals(type, "foo/bar"); }
@Test public void qualityFactor5(){ AcceptHeader acceptHeader = new AcceptHeader("application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); String type = acceptHeader.select("text/html", "image/png"); Assert.assertNotNull(type); Assert.assertEquals(type, "image/png"); type = acceptHeader.select("text/plain", "image/png"); Assert.assertNotNull(type); Assert.assertEquals(type, "image/png"); type = acceptHeader.select("text/html", "image/png"); Assert.assertNotNull(type); Assert.assertEquals(type, "image/png"); type = acceptHeader.select("text/plain", "image/png","application/xml"); Assert.assertNotNull(type); Assert.assertEquals(type, "image/png"); }
@Test public void qualityFactor6(){ AcceptHeader acceptHeader = new AcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); String type = acceptHeader.select("text/plain", "text/html"); Assert.assertNotNull(type); Assert.assertEquals(type, "text/html"); type = acceptHeader.select("text/plain", "application/xml"); Assert.assertNotNull(type); Assert.assertEquals(type, "application/xml"); }
@Test public void headerSelect1() { String type = new AcceptHeader("text/html").select("text/html", "text/plain"); Assert.assertNotNull(type); Assert.assertEquals("text/html", type); }
@Test public void headerSelect2() { String type = new AcceptHeader("text/*").select("text/html"); Assert.assertNotNull(type); Assert.assertEquals("text/html", type); }
@Test(expected = HttpResponses.HttpResponseException.class) public void headerSelectUnsupportedMediaType() { new AcceptHeader("text/html").select("application/json"); }
@Test public void wildCard() { String type = new AcceptHeader("text/*").select("text/html"); Assert.assertNotNull(type); Assert.assertEquals("text/html", type); }
@Test public void qualityFactor1() { String type = new AcceptHeader("image/*;q=0.5, image/png;q=1").select("image/jpeg", "image/png"); Assert.assertNotNull(type); Assert.assertEquals(type, "image/png"); }
@Test public void qualityFactor2() { String type = new AcceptHeader("text/*;q=0.5, *;q=0.1").select("application/xbel+xml", "text/xml"); Assert.assertNotNull(type); Assert.assertEquals(type, "text/xml"); }
@Test public void qualityFactor3() { String type = new AcceptHeader("text/xml;q=0.5, application/json;q=0.1, text/html;q=0.1").select("application/json", "text/xml"); Assert.assertNotNull(type); Assert.assertEquals(type, "text/xml"); }