### Question:
AmbariHandlerList extends HandlerCollection implements ViewInstanceHandlerList { @Override public void removeViewInstance(ViewInstanceEntity viewInstanceDefinition) { Handler handler = viewHandlerMap.get(viewInstanceDefinition); if (handler != null) { viewHandlerMap.remove(viewInstanceDefinition); removeHandler(handler); } } 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 testRemoveViewInstance() 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); 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)); handlerList.removeViewInstance(viewInstanceEntity); handlers = new ArrayList<>(Arrays.asList(handlerList.getHandlers())); Assert.assertFalse(handlers.contains(handler)); verify(handler, server, sessionHandler); }