### Question:
AmbariHandlerList extends HandlerCollection implements ViewInstanceHandlerList { @Override public void addViewInstance(ViewInstanceEntity viewInstanceDefinition) throws SystemException { WebAppContext handler = getHandler(viewInstanceDefinition); viewHandlerMap.put(viewInstanceDefinition, handler); super.addHandler(handler); if(!isStopped() && !isStopping()) { try { handler.start(); } catch (Exception e) { throw new SystemException("Caught exception adding a view instance.", e); } } handler.getSessionHandler().setSessionCache(sessionHandler.getSessionCache()); } 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 testAddViewInstance() throws Exception { ViewInstanceEntity viewInstanceEntity = ViewInstanceEntityTest.getViewInstanceEntity(); final WebAppContext handler = createNiceMock(WebAppContext.class); Server server = createNiceMock(Server.class); expect(handler.getServer()).andReturn(server); expect(handler.getChildHandlers()).andReturn(new Handler[]{}); expect(handler.getSessionHandler()).andReturn(createNiceMock(SessionHandler.class)); handler.setServer(null); expect(sessionHandler.getSessionCache()).andReturn(sessionCache); Capture<FilterHolder> securityHeaderFilterCapture = EasyMock.newCapture(); Capture<FilterHolder> persistFilterCapture = EasyMock.newCapture(); Capture<FilterHolder> securityFilterCapture = EasyMock.newCapture(); handler.addFilter(capture(securityHeaderFilterCapture), eq("/*"), eq(AmbariServer.DISPATCHER_TYPES)); handler.addFilter(capture(persistFilterCapture), eq("/*"), eq(AmbariServer.DISPATCHER_TYPES)); handler.addFilter(capture(securityFilterCapture), eq("/*"), eq(AmbariServer.DISPATCHER_TYPES)); handler.setAllowNullPathInfo(true); replay(handler, server, sessionHandler); AmbariHandlerList handlerList = getAmbariHandlerList(handler); handlerList.addViewInstance(viewInstanceEntity); ArrayList<Handler> handlers = new ArrayList<>(Arrays.asList(handlerList.getHandlers())); Assert.assertTrue(handlers.contains(handler)); Assert.assertEquals(ambariViewsSecurityHeaderFilter, securityHeaderFilterCapture.getValue().getFilter()); Assert.assertEquals(persistFilter, persistFilterCapture.getValue().getFilter()); Assert.assertEquals(springSecurityFilter, securityFilterCapture.getValue().getFilter()); verify(handler, server, sessionHandler); }