### Question:
ResourceRenderer { public void renderFile(final HttpServletRequest request, final HttpServletResponse response, final File resourceFile, final APISession apiSession) throws CompilationFailedException, IllegalAccessException, IOException, BonitaException { byte[] content; response.setCharacterEncoding("UTF-8"); try { content = getFileContent(resourceFile, response); response.setContentType(request.getSession().getServletContext() .getMimeType(resourceFile.getName())); response.setContentLength(content.length); response.setBufferSize(content.length); try (OutputStream out = response.getOutputStream()) { out.write(content, 0, content.length); } response.flushBuffer(); }catch (final FileNotFoundException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); }catch (final IOException e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Error while generating the response.", e); } throw new BonitaException(e.getMessage(), e); } }  void renderFile(final HttpServletRequest request, final HttpServletResponse response, final File resourceFile, final APISession apiSession); List<String> getPathSegments(final String pathInfo);  }### Answer:
@Test public void renderFile_should_build_a_valid_response() throws BonitaException, URISyntaxException, IOException, IllegalAccessException, InstantiationException { final File resourceFile = getResourceFile(); final long contentLength = resourceFile.length(); when(servletContext.getMimeType("file.css")).thenReturn("text/css"); resourceRenderer.renderFile(req, res, resourceFile, apiSession); verify(res).setCharacterEncoding("UTF-8"); verify(servletContext).getMimeType("file.css"); verify(res).setContentType("text/css"); verify(res).setContentLength((int) contentLength); verify(res).setBufferSize((int) contentLength); verify(outputStream).write(any(byte[].class), eq(0), eq((int) contentLength)); verify(res).flushBuffer(); verify(outputStream).close(); }
@Test(expected = BonitaException.class) public void renderFile_should_throw_bonita_exception_on_ioexception() throws BonitaException, URISyntaxException, IOException, IllegalAccessException, InstantiationException { final File resourceFile = getResourceFile(); doThrow(new IOException()).when(outputStream).write(any(byte[].class), any(int.class), any(int.class)); resourceRenderer.renderFile(req, res, resourceFile, apiSession); }
@Test(expected = BonitaException.class) public void getResourceFile_should_throw_BonitaException_on_passing_null_resources_folder() throws Exception { resourceRenderer.renderFile(req, res, null, apiSession); }
@Test public void getResourceFile_should_sendError404_on_passing_none_existing_resources() throws Exception { final File noneExistingFile = new File("NoneExistingFile.css"); resourceRenderer.renderFile(req, res, noneExistingFile, apiSession); verify(res).sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot find the resource file " + noneExistingFile.getName()); }