### Question:
AliasHandler extends JettyHandler { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (pathAliases.containsKey(target)) { String newTarget = pathAliases.get(target); ServletContext context = request.getServletContext().getContext(newTarget); String newPath = newTarget.substring(context.getContextPath().length()); context.getRequestDispatcher(newPath).forward(request, response); return; } super.handle(target, baseRequest, request, response); } AliasHandler(TransportCommandProcessor<HttpCommand> commandProcessor, boolean suppressCommasInAccessLog, Map<String, String> pathAliases); @Override void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response);  }### Answer:
@Test public void aliasMiss() throws Exception { AliasHandler handler = new AliasHandler(commandProcessor, true, pathAliases); Continuation continuation = mock(Continuation.class); when(request.getAttribute(Continuation.ATTRIBUTE)).thenReturn(continuation); handler.handle("/missPath", baseRequest, request, response); verify(commandProcessor, times(1)).process(any(HttpCommand.class)); }
@Test public void aliasHit() throws IOException, ServletException { AliasHandler handler = new AliasHandler(commandProcessor, true, pathAliases); pathAliases.put("/hitPath","/context/alternatePath"); ServletContext origContext = mock(ServletContext.class); ServletContext newContext = mock(ServletContext.class); when(request.getServletContext()).thenReturn(origContext); ArgumentCaptor<String> requestContextPath = ArgumentCaptor.forClass(String.class); when(origContext.getContext(requestContextPath.capture())).thenReturn(newContext); when(newContext.getContextPath()).thenReturn("/context"); RequestDispatcher requestDispatcher = mock(RequestDispatcher.class); ArgumentCaptor<String> requestDispatcherPath = ArgumentCaptor.forClass(String.class); when(newContext.getRequestDispatcher(requestDispatcherPath.capture())).thenReturn(requestDispatcher); handler.handle("/hitPath",baseRequest,request,response); verify(requestDispatcher, times(1)).forward(request, response); assertEquals("/context/alternatePath", requestContextPath.getValue()); assertEquals("/alternatePath", requestDispatcherPath.getValue()); }