Search in sources :

Example 1 with HasErrorParameter

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

the class VaadinServletContextInitializerTest method errorParameterServletContextListenerEvent_hasCustomRouteNotFoundViewImplementingHasErrorParameter_customRouteNotFoundViewIsRegistered.

@Test
public void errorParameterServletContextListenerEvent_hasCustomRouteNotFoundViewImplementingHasErrorParameter_customRouteNotFoundViewIsRegistered() throws Exception {
    // given
    initDefaultMocks();
    VaadinServletContextInitializer initializer = getStubbedVaadinServletContextInitializer();
    Runnable when = initRouteNotFoundMocksAndGetContextInitializedMockCall(initializer);
    class TestErrorView extends Component implements HasErrorParameter<NotFoundException> {

        @Override
        public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<NotFoundException> parameter) {
            return 0;
        }
    }
    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) ErrorParameter(com.vaadin.flow.router.ErrorParameter) HasErrorParameter(com.vaadin.flow.router.HasErrorParameter) BeforeEnterEvent(com.vaadin.flow.router.BeforeEnterEvent) Component(com.vaadin.flow.component.Component) HasErrorParameter(com.vaadin.flow.router.HasErrorParameter) ApplicationRouteRegistry(com.vaadin.flow.server.startup.ApplicationRouteRegistry) Test(org.junit.Test)

Aggregations

Component (com.vaadin.flow.component.Component)1 BeforeEnterEvent (com.vaadin.flow.router.BeforeEnterEvent)1 ErrorParameter (com.vaadin.flow.router.ErrorParameter)1 HasErrorParameter (com.vaadin.flow.router.HasErrorParameter)1 NotFoundException (com.vaadin.flow.router.NotFoundException)1 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)1 ApplicationRouteRegistry (com.vaadin.flow.server.startup.ApplicationRouteRegistry)1 Test (org.junit.Test)1