Application { public void destroy() { uiContexts.values().forEach(uiContext -> { try { uiContext.destroyFromApplication(); } catch (final Exception e) { log.error("Can't destroy the UIContext #" + uiContext.getID() + " on Application #" + id, e); } }); uiContexts.clear(); try { log.info("Invalidate session on Application #{} because all ui contexts have been destroyed", id); session.invalidate(); } catch (final IllegalArgumentException e) { log.error("The session is already invalid", e); } SessionManager.get().unregisterApplication(this); } Application(final String id, final HttpSession session, final ApplicationConfiguration configuration); void registerUIContext(final UIContext uiContext); void deregisterUIContext(final int uiContextID); void destroy(); UIContext getUIContext(final int uiContextID); Collection<UIContext> getUIContexts(); void pushToClients(final Object message); void setAttribute(final String name, final Object value); T getAttribute(final String name); ApplicationConfiguration getOptions(); String getId(); int countUIContexts(); @Override String toString();  }
@Test public void testDestroy() { final int uiContextID1 = 1; final UIContext uiContext1 = Mockito.mock(UIContext.class); Mockito.when(uiContext1.getID()).thenReturn(uiContextID1); application.registerUIContext(uiContext1); application.destroy(); assertEquals(0, application.countUIContexts()); assertEquals(0, application.getUIContexts().size()); }