ResponseWriter implements Serializable { void writeContentType(String filenameWithPath, ServletRequest request, ServletResponse response) { String mimetype = request.getServletContext() .getMimeType(filenameWithPath); if (mimetype != null) { response.setContentType(mimetype); } } ResponseWriter(DeploymentConfiguration deploymentConfiguration); private  ResponseWriter(int bufferSize, boolean brotliEnabled); void writeResponseContents(String filenameWithPath, URL resourceUrl,
            HttpServletRequest request, HttpServletResponse response);  }
@Test public void contentType() { AtomicReference<String> contentType = new AtomicReference<>(null); Mockito.doAnswer(invocation -> { contentType.set((String) invocation.getArguments()[0]); return null; }).when(response).setContentType(Matchers.anyString()); Mockito.when(servletContext.getMimeType("/file.png")) .thenReturn("image/png"); responseWriter.writeContentType("/file.png", request, response); Assert.assertEquals("image/png", contentType.get()); }
@Test public void noContentType() { AtomicReference<String> contentType = new AtomicReference<>(null); Mockito.doAnswer(invocation -> { contentType.set((String) invocation.getArguments()[0]); return null; }).when(response).setContentType(Matchers.anyString()); Mockito.when(servletContext.getMimeType("/file")).thenReturn(null); responseWriter.writeContentType("/file", request, response); Assert.assertNull(contentType.get()); }