MessageFileHandler { public void writeFileNamesToResponse(final HttpServletResponse resp, final Path path) throws IOException { FileListJsonProperties properties = configurationAccess.getProperties().getFileListProperties(); PrintWriter out = resp.getWriter(); resp.setContentType(APPLICATION_JSON); out.write(messageFileJsonBuilder.buildMessageFileListJson(path.toFile(), properties.getMaximumCountOfMessages())); out.flush(); out.close(); }  void writeFileNamesToResponse(final HttpServletResponse resp, final Path path); void writeFileContentToResponse(final HttpServletRequest req, final HttpServletResponse resp, final String pathInfo, final Path path);  }
@Test public void testWriteFileNamesToResponse() throws IOException { String expectedJson = "{\"test\":\"test\"}"; given(fileListProperties.getMaximumCountOfMessages()).willReturn(10); given(path.toFile()).willReturn(file); given(messageFileJsonBuilder.buildMessageFileListJson(file, 10)).willReturn(expectedJson); underTest.writeFileNamesToResponse(response, path); verify(response).setContentType(APPLICATION_JSON); verify(messageFileJsonBuilder).buildMessageFileListJson(file, 10); verify(printWriter).write(expectedJson); verify(printWriter).flush(); }