/** * Tests closing the only open window. * * @throws Exception if the test fails */ @Test public void closeTheOnlyWindow() throws Exception { final WebClient webClient = new WebClient(); final EventCatcher eventCatcher = new EventCatcher(); eventCatcher.listenTo(webClient); final WebWindow windowToClose = webClient.getCurrentWindow(); ((TopLevelWindow) windowToClose).close(); final List<WebWindowEvent> expectedEvents = Arrays.asList(new WebWindowEvent(windowToClose, WebWindowEvent.CLOSE, null, null)); assertEquals(expectedEvents, eventCatcher.getEvents()); // Since this was the only open window, a new window should have // been created when this one was closed. Verify this. assertNotNull(webClient.getCurrentWindow()); assertNotSame(webClient.getCurrentWindow(), windowToClose); assertEquals(1, webClient.getWebWindows().size()); }