MessageHandlerServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { Path path = filePathProvider.getLogFilePath(); if (pathIsEmpty(req)) { messageFileHandler.writeFileNamesToResponse(resp, path); } else { messageFileHandler.writeFileContentToResponse(req, resp, req.getPathInfo(), path); } } @Autowired  MessageHandlerServlet(LogFilePathProvider filePathProvider, MessageFileHandler messageFileHandler);   }
@Test public final void testDoGetShouldCallWriteFileNamesToResponseWhenPathIsEmpty() throws ServletException, IOException { given(request.getPathInfo()).willReturn(null); underTest.doGet(request, response); verify(messageFileHandler).writeFileNamesToResponse(response, path); }
@Test public final void testDoGetShouldCallWriteFileContentToResponseWhenPathIsNotEmpty() throws ServletException, IOException { String pathInfo = "/filename"; given(request.getPathInfo()).willReturn(pathInfo); underTest.doGet(request, response); verify(messageFileHandler).writeFileContentToResponse(request, response, pathInfo, path); }