UI extends Component implements PollNotifier, HasComponents, RouterLayout { public void navigate(Class<? extends Component> navigationTarget) { navigate(navigationTarget, RouteParameters.empty()); } UI(); protected  UI(UIInternalUpdater internalsHandler); VaadinSession getSession(); int getUIId(); void doInit(VaadinRequest request, int uiId); static void setCurrent(UI ui); static UI getCurrent(); void close(); boolean isClosing(); void accessSynchronously(Command command); Future<Void> access(final Command command); SerializableRunnable accessLater(SerializableRunnable accessTask,
            SerializableRunnable detachHandler); SerializableConsumer<T> accessLater(
            SerializableConsumer<T> accessTask,
            SerializableRunnable detachHandler); void setPollInterval(int intervalInMillis); int getPollInterval(); LoadingIndicatorConfiguration getLoadingIndicatorConfiguration(); void push(); PushConfiguration getPushConfiguration(); ReconnectDialogConfiguration getReconnectDialogConfiguration(); @Override Locale getLocale(); void setLocale(Locale locale); void setDirection(Direction direction); @Override Element getElement(); UIInternals getInternals(); Page getPage(); void navigate(Class<? extends Component> navigationTarget); void navigate(
            Class<? extends C> navigationTarget, T parameter); void navigate(Class<? extends Component> navigationTarget,
            RouteParameters parameters); void navigate(String location); void navigate(String location, QueryParameters queryParameters); boolean isNavigationSupported(); @Deprecated Router getRouter(); ExecutionRegistration beforeClientResponse(Component component,
            SerializableConsumer<ExecutionContext> execution); @Override void add(Component... components); @Override Optional<UI> getUI(); Registration addBeforeEnterListener(BeforeEnterListener listener); Registration addBeforeLeaveListener(BeforeLeaveListener listener); Registration addAfterNavigationListener(
            AfterNavigationListener listener); List<E> getNavigationListeners(Class<E> navigationHandler); ShortcutRegistration addShortcutListener(Command command, Key key,
            KeyModifier... keyModifiers); ShortcutRegistration addShortcutListener(
            ShortcutEventListener listener, Key key,
            KeyModifier... keyModifiers); Component getActiveDragSourceComponent(); String getCsrfToken();  }
@Test public void navigateWithParameters_delegateToRouter() { final String route = "params"; Router router = Mockito.mock(Router.class); UI ui = new MockUI(router); QueryParameters params = QueryParameters .simple(Collections.singletonMap("test", "indeed")); ArgumentCaptor<Location> location = ArgumentCaptor .forClass(Location.class); ui.navigate(route, params); Mockito.verify(router).navigate(Matchers.eq(ui), location.capture(), Matchers.eq(NavigationTrigger.UI_NAVIGATE)); Location value = location.getValue(); Assert.assertEquals(route, value.getPath()); Assert.assertEquals(params, value.getQueryParameters()); }
@Test public void navigate_useParameterizedTarget_noOptionalAnnotation_navigationSucceded() { AtomicReference<String> loc = new AtomicReference<>(); UI ui = new UI() { @Override public void navigate(String location) { loc.set(location); } }; initUI(ui, "", null); ui.navigate(Parameterized.class, "baz"); Assert.assertEquals("foo-bar/baz", loc.get()); }
@Test public void navigate_throws_illegal_argument_exception() { UI ui = new UI(); initUI(ui, "", null); try { ui.navigate(Parameterized.class); Assert.fail("IllegalArgumentException expected."); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("requires a parameter.")); } try { ui.navigate(Parameterized.class, (String) null); Assert.fail("IllegalArgumentException expected."); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("requires a parameter.")); } try { ui.navigate(Parameterized.class, RouteParameters.empty()); Assert.fail("IllegalArgumentException expected."); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("requires a parameter.")); } try { ui.navigate(Parameterized.class, new RouteParameters("some", "value")); Assert.fail("IllegalArgumentException expected."); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("requires a parameter.")); } }
@Test public void navigate_throws_null_pointer_exception() { UI ui = new UI(); initUI(ui, "", null); try { ui.navigate((String) null); Assert.fail("NullPointerException expected."); } catch (NullPointerException e) { Assert.assertEquals("Location must not be null", e.getMessage()); } try { ui.navigate((String) null, QueryParameters.empty()); Assert.fail("NullPointerException expected."); } catch (NullPointerException e) { Assert.assertEquals("Location must not be null", e.getMessage()); } try { ui.navigate("foo-bar", null); Assert.fail("NullPointerException expected."); } catch (NullPointerException e) { Assert.assertEquals("Query parameters must not be null", e.getMessage()); } }
@Test public void navigate_throws_not_found_exception() { UI ui = new UI(); initUI(ui, "", null); try { ui.navigate(FooBarParamNavigationTarget.class); Assert.fail("NotFoundException expected."); } catch (NotFoundException e) { } try { ui.navigate(ParameterizedNotRoute.class, 1); Assert.fail("NotFoundException expected."); } catch (NotFoundException e) { } try { ui.navigate(FooBarParamNavigationTarget.class, new RouteParameters("fooParam", "123")); Assert.fail("NotFoundException expected."); } catch (NotFoundException e) { } }