Search in sources :

Example 1 with RouteNotFoundError

use of com.vaadin.flow.router.RouteNotFoundError in project flow by vaadin.

the class VaadinServletContextInitializerTest method errorParameterServletContextListenerEvent_hasCustomRouteNotFoundViewExtendingRouteNotFoundError_customRouteNotFoundViewIsRegistered.

@Test
public void errorParameterServletContextListenerEvent_hasCustomRouteNotFoundViewExtendingRouteNotFoundError_customRouteNotFoundViewIsRegistered() throws Exception {
    // given
    initDefaultMocks();
    VaadinServletContextInitializer initializer = getStubbedVaadinServletContextInitializer();
    Runnable when = initRouteNotFoundMocksAndGetContextInitializedMockCall(initializer);
    class TestErrorView extends RouteNotFoundError {
    }
    Mockito.doAnswer(invocation -> Stream.of(TestErrorView.class)).when(initializer).findBySuperType(Mockito.anyCollection(), Mockito.eq(HasErrorParameter.class));
    // when
    when.run();
    // then
    ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(new VaadinServletContext(servletContext));
    final Class<? extends Component> navigationTarget = registry.getErrorNavigationTarget(new NotFoundException()).get().getNavigationTarget();
    Assert.assertEquals(TestErrorView.class, navigationTarget);
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) NotFoundException(com.vaadin.flow.router.NotFoundException) RouteNotFoundError(com.vaadin.flow.router.RouteNotFoundError) HasErrorParameter(com.vaadin.flow.router.HasErrorParameter) ApplicationRouteRegistry(com.vaadin.flow.server.startup.ApplicationRouteRegistry) Test(org.junit.Test)

Aggregations

HasErrorParameter (com.vaadin.flow.router.HasErrorParameter)1 NotFoundException (com.vaadin.flow.router.NotFoundException)1 RouteNotFoundError (com.vaadin.flow.router.RouteNotFoundError)1 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)1 ApplicationRouteRegistry (com.vaadin.flow.server.startup.ApplicationRouteRegistry)1 Test (org.junit.Test)1