### Question:
UploadFiles extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("Entro al doGet"); String fileName = request.getParameter("filename"); if(fileName == null || fileName.equals("")){ throw new ServletException("File Name can't be null or empty"); } File file = new File(request.getSession().getServletContext().getAttribute("FILES_DIR")+File.separator+fileName); if(!file.exists()){ throw new ServletException("File doesn't exists on server."); } ServletContext ctx = getServletContext(); InputStream fis = new FileInputStream(file); String mimeType = ctx.getMimeType(file.getAbsolutePath()); response.setContentType("application/force-download"); response.setDateHeader("Expires", 0); response.setContentType(mimeType != null? mimeType:"application/octet-stream"); response.setContentLength((int) file.length()); response.setHeader("Content-Transfer-Encoding", "binary"); response.setHeader("Cache-Control", "private"); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); ServletOutputStream os = response.getOutputStream(); byte[] bufferData = new byte[1024]; int read=0; while((read = fis.read(bufferData))!= -1){ os.write(bufferData, 0, read); } os.flush(); os.close(); fis.close(); System.out.println("File downloaded at client successfully"); }  void init(ServletConfig config);  }### Answer:
@Test public void testDoGet() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpSession sesion = mock(HttpSession.class); ServletConfig config = mock(ServletConfig.class); ServletContext context = mock(ServletContext.class); RequestDispatcher dispatcher = mock(RequestDispatcher.class); ServletOutputStream stream = mock(ServletOutputStream.class); when(config.getServletContext()).thenReturn(context); when(sesion.getServletContext()).thenReturn(context); when(context.getRequestDispatcher("/interface.jsp")).thenReturn(dispatcher); when(context.getAttribute("FILES_DIR")).thenReturn(""); URL url = this.getClass().getResource("/prueba.txt"); File testFile = new File(url.getFile()); when(request.getParameter("filename")).thenReturn(testFile.getAbsolutePath()); when(request.getSession()).thenReturn(sesion); when(response.getOutputStream()).thenReturn(stream); UploadFiles fileUp = new UploadFiles(); try { fileUp.init(config); fileUp.doGet(request, response); } catch (ServletException ex) { fail("Should not raise exception " + ex.toString()); } catch (IOException ex) { fail("Should not raise exception " + ex.toString()); } }