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);
}
Aggregations