### Question:
DownloadFileServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource suffixResource = request.getRequestPathInfo().getSuffixResource(); if (suffixResource != null) { response.setContentType(suffixResource.getValueMap().get("jcr:content/jcr:mimeType", "")); response.setHeader("Content-Disposition", "attachment; " + suffixResource.getName()); IOUtils.copy(suffixResource.adaptTo(InputStream.class), response.getOutputStream()); } else { response.sendError(404); } }    }### Answer:
@Test public void testValidRequest() throws ServletException, IOException { context.requestPathInfo().setSuffix("/content/apache/sling-apache-org/index/apache.png"); DownloadFileServlet dfs = new DownloadFileServlet(); dfs.doGet(context.request(), context.response()); assertEquals(200, context.response().getStatus()); assertTrue(context.response().getHeaderNames().contains("Content-Disposition")); }
@Test public void testInValidRequest() throws ServletException, IOException { context.requestPathInfo().setSuffix("/content/apache/sling-apache-org/index/notafile.png"); DownloadFileServlet dfs = new DownloadFileServlet(); dfs.doGet(context.request(), context.response()); assertEquals(404, context.response().getStatus()); assertFalse(context.response().getHeaderNames().contains("Content-Disposition")); }