Application { public void deregisterUIContext(final int uiContextID) { if (uiContexts.remove(uiContextID) != null && uiContexts.isEmpty()) { try { session.invalidate(); } catch (final IllegalStateException e) { log.warn("Issue when unregistering UIContext #{} : Session {} already invalidated", uiContextID, session.getId()); } 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 testDeregisterUIContext() { final int uiContextID1 = 1; final UIContext uiContext1 = Mockito.mock(UIContext.class); Mockito.when(uiContext1.getID()).thenReturn(uiContextID1); application.registerUIContext(uiContext1); final int uiContextID2 = 2; final UIContext uiContext2 = Mockito.mock(UIContext.class); Mockito.when(uiContext2.getID()).thenReturn(uiContextID2); application.registerUIContext(uiContext2); application.deregisterUIContext(uiContext2.getID()); assertEquals(1, application.countUIContexts()); assertEquals(1, application.getUIContexts().size()); assertEquals(uiContext1, application.getUIContext(uiContextID1)); application.deregisterUIContext(uiContext1.getID()); assertEquals(0, application.countUIContexts()); assertTrue(application.getUIContexts().isEmpty()); }