DefaultAcceptHeaderToFormat implements AcceptHeaderToFormat { public String getFormat(String acceptHeader) { if (acceptHeader == null || acceptHeader.trim().equals("")) { return DEFAULT_FORMAT; } if (acceptHeader.contains(DEFAULT_FORMAT)) { return DEFAULT_FORMAT; } if (acceptToFormatCache.containsKey(acceptHeader)) { return acceptToFormatCache.get(acceptHeader); } return chooseMimeType(acceptHeader); } DefaultAcceptHeaderToFormat(); String getFormat(String acceptHeader);  }
@Test public void shouldComplainIfThereIsNothingRegistered() { Assert.assertEquals("unknown", mimeTypeToFormat.getFormat("unknown")); }
@Test public void shouldReturnHtmlWhenRequestingAnyContentType() { Assert.assertEquals("html", mimeTypeToFormat.getFormat("*/*")); }
@Test public void shouldReturnHtmlWhenAcceptsIsBlankContentType() { Assert.assertEquals("html", mimeTypeToFormat.getFormat("")); }
@Test public void shouldReturnHtmlWhenRequestingUnknownAsFirstAndAnyContentType() { Assert.assertEquals("html", mimeTypeToFormat.getFormat("unknow, */*")); }
@Test public void testHtml() { Assert.assertEquals("html", mimeTypeToFormat.getFormat("text/html")); }
@Test public void testJson() { Assert.assertEquals("json", mimeTypeToFormat.getFormat("application/json")); }
@Test public void testJsonWithQualifier() { Assert.assertEquals("json", mimeTypeToFormat.getFormat("application/json; q=0.4")); }
@Test public void testNull() { Assert.assertEquals("html", mimeTypeToFormat.getFormat(null)); }
@Test public void testJsonInAComplexAcceptHeader() { Assert.assertEquals("json", mimeTypeToFormat.getFormat("application/json, text/javascript, */*")); }
@Test public void testPrecendenceInAComplexAcceptHeaderHtmlShouldPrevailWhenTied() { Assert.assertEquals("html", mimeTypeToFormat.getFormat("application/json, text/html, */*")); }
@Test public void testPrecendenceInABizzarreMSIE8AcceptHeader() { Assert.assertEquals("html", mimeTypeToFormat.getFormat("image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*")); }
@Test public void testPrecendenceInABizzarreMSIE8AcceptHeaderWithHtml() { Assert.assertEquals("html", mimeTypeToFormat.getFormat("image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, text/html, */*")); }
@Test public void testPrecendenceInAComplexAcceptHeaderHtmlShouldPrevailWhenTied2() { Assert.assertEquals("html", mimeTypeToFormat.getFormat("text/html, application/json, */*")); }
@Test public void testJsonInAComplexAcceptHeaderWithParameters() { Assert.assertEquals("json", mimeTypeToFormat.getFormat("application/json; q=0.7, application/xml; q=0.1, */*")); }
@Test public void testXMLInAComplexAcceptHeaderWithParametersNotOrdered() { Assert.assertEquals("xml", mimeTypeToFormat.getFormat("application/json; q=0.1, application/xml; q=0.7, */*")); }