ConfServlet extends HttpServlet { @VisibleForTesting static String parseAcceptHeader(HttpServletRequest request) { String format = request.getHeader(HttpHeaders.ACCEPT); return format != null && format.contains(FORMAT_JSON) ? FORMAT_JSON : FORMAT_XML; }  @Override void doGet(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testParseHeaders() throws Exception { HashMap<String, String> verifyMap = new HashMap<String, String>(); verifyMap.put("text/plain", ConfServlet.FORMAT_XML); verifyMap.put(null, ConfServlet.FORMAT_XML); verifyMap.put("text/xml", ConfServlet.FORMAT_XML); verifyMap.put("application/xml", ConfServlet.FORMAT_XML); verifyMap.put("application/json", ConfServlet.FORMAT_JSON); HttpServletRequest request = Mockito.mock(HttpServletRequest.class); for(String contentTypeExpected : verifyMap.keySet()) { String contenTypeActual = verifyMap.get(contentTypeExpected); Mockito.when(request.getHeader(HttpHeaders.ACCEPT)) .thenReturn(contentTypeExpected); assertEquals(contenTypeActual, ConfServlet.parseAcceptHeader(request)); } }