Page implements Serializable { public void setLocation(String uri) { open(uri, "_self"); } Page(UI ui); void setTitle(String title); void addStyleSheet(String url); void addStyleSheet(String url, LoadMode loadMode); void addJavaScript(String url); void addJavaScript(String url, LoadMode loadMode); void addJsModule(String url); void addDynamicImport(String expression); @Deprecated ExecutionCanceler executeJavaScript(String expression,
            Serializable... parameters); PendingJavaScriptResult executeJs(String expression,
            Serializable... parameters); History getHistory(); void reload(); Registration addBrowserWindowResizeListener(
            BrowserWindowResizeListener resizeListener); void open(String url); void open(String url, String windowName); void setLocation(String uri); void setLocation(URI uri); void retrieveExtendedClientDetails(
            ExtendedClientDetailsReceiver receiver);  }
@Test public void open_openInSameWindow_closeTheClientApplication() { AtomicReference<String> capture = new AtomicReference<>(); List<Serializable> params = new ArrayList<>(); Page page = new Page(new MockUI()) { @Override public PendingJavaScriptResult executeJs(String expression, Serializable[] parameters) { capture.set(expression); params.addAll(Arrays.asList(parameters)); return Mockito.mock(PendingJavaScriptResult.class); } }; page.setLocation("foo"); Assert.assertEquals("_self", params.get(1)); Assert.assertThat(capture.get(), CoreMatchers .startsWith("if ($1 == '_self') this.stopApplication();")); }