DesktopWindowManager { public void closeActiveWindow() { final List<Widget> reverse = Lists.reverse(windowManager.getStack()); for (Widget w : reverse) { if (w instanceof Window) { ((Window) w).hide(); return; } } } @Inject  DesktopWindowManager(final WindowManager windowManager,
                         final WindowFactory windowFactory); void closeActiveWindow(); void show(final WindowState windowState); void show(WindowType windowType); void show(final WindowConfig config, final boolean updateExistingWindow); void stickWindowToTop(Window window);  }
@Test public void closeActiveWindowOnlyClosesActiveWindow() { Window window1 = mock(Window.class); Window window2 = mock(Window.class); Window window3 = mock(Window.class); Window window4 = mock(Window.class); final Stack<Widget> windowStack = new Stack<>(); windowStack.push(window1); windowStack.push(window2); windowStack.push(window3); windowStack.push(window4); when(windowManagerMock.getStack()).thenReturn(windowStack); uut.closeActiveWindow(); verify(windowManagerMock).getStack(); verify(window1, never()).hide(); verify(window2, never()).hide(); verify(window3, never()).hide(); verify(window4).hide(); verifyNoMoreInteractions(windowManagerMock); }