### Question:
AmbariHandlerList extends HandlerCollection implements ViewInstanceHandlerList { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ViewEntity viewEntity = getTargetView(target); if (viewEntity == null) { processHandlers(target, baseRequest, request, response); } else { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader viewClassLoader = viewEntity.getClassLoader(); if (viewClassLoader == null) { LOG.debug("No class loader associated with view {}.", viewEntity.getName()); } else { Thread.currentThread().setContextClassLoader(viewClassLoader); } processHandlers(target, baseRequest, request, response); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } } } AmbariHandlerList(); @Override void handle(String target, Request baseRequest,
                     HttpServletRequest request, HttpServletResponse response); @Override void addHandler(Handler handler); @Override void addViewInstance(ViewInstanceEntity viewInstanceDefinition); @Override void shareSessionCacheToViews(SessionCache serverSessionCache); @Override void removeViewInstance(ViewInstanceEntity viewInstanceDefinition);  }### Answer:
@Test public void testHandle() throws Exception { final WebAppContext handler = createNiceMock(WebAppContext.class); ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class); ViewEntity viewEntity = createNiceMock(ViewEntity.class); ClassLoader classLoader = createNiceMock(ClassLoader.class); Request baseRequest = createNiceMock(Request.class); HttpServletRequest request = createNiceMock(HttpServletRequest.class); HttpServletResponse response = createNiceMock(HttpServletResponse.class); expect(viewRegistry.getDefinition("TEST", "1.0.0")).andReturn(viewEntity).anyTimes(); expect(viewEntity.getClassLoader()).andReturn(classLoader).anyTimes(); expect(handler.isStarted()).andReturn(true).anyTimes(); expect(handler.getChildHandlers()).andReturn(new Handler[]{}); replay(handler, viewRegistry, viewEntity); handler.handle("/api/v1/views/TEST/versions/1.0.0/instances/INSTANCE_1/resources/test", baseRequest, request, response); AmbariHandlerList handlerList = getAmbariHandlerList(handler); handlerList.viewRegistry = viewRegistry; handlerList.start(); handlerList.addHandler(handler); handlerList.handle("/api/v1/views/TEST/versions/1.0.0/instances/INSTANCE_1/resources/test", baseRequest, request, response); verify(handler, viewRegistry, viewEntity); }