Page implements Serializable { public void addJsModule(String url) { if (UrlUtil.isExternal(url) || url.startsWith("/")) { addDependency(new Dependency(Type.JS_MODULE, url, LoadMode.EAGER)); } else { throw new IllegalArgumentException( "url argument must contains either a protocol (eg. starts with \"http: } } 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 addJsModule_accepts_onlyExternalAndStartingSlash() { List<String> urls = new LinkedList<>(); urls.add("http: urls.add("https: urls.add(" urls.add("/mod.js"); for (String url : urls) { page.addJsModule(url); } Collection<Dependency> pendingSendToClient = ui.getInternals() .getDependencyList().getPendingSendToClient(); Assert.assertEquals("There should be 4 dependencies added.", 4, pendingSendToClient.size()); for (Dependency dependency : pendingSendToClient) { Assert.assertEquals("Dependency should be a JSModule", Dependency.Type.JS_MODULE, dependency.getType()); Assert.assertEquals("JS module dependency should be EAGER", LoadMode.EAGER, dependency.getLoadMode()); Assert.assertTrue( "Dependency " + dependency.getUrl() + " is not found in the source list.", urls.contains(dependency.getUrl())); urls.remove(dependency.getUrl()); } Assert.assertEquals("Not all urls were added as dependencies", 0, urls.size()); }
@Test public void addJsModule_rejects_files() { try { page.addJsModule("mod.js"); Assert.fail( "Adding a file without starting \"/\" is not to be allowed."); } catch (IllegalArgumentException e) { } }