RouteUtil { public static void updateRouteRegistry(RouteRegistry registry, Set<Class<?>> addedClasses, Set<Class<?>> modifiedClasses, Set<Class<?>> deletedClasses) { RouteConfiguration routeConf = RouteConfiguration.forRegistry(registry); Logger logger = LoggerFactory.getLogger(RouteUtil.class); registry.update(() -> { Stream.concat(deletedClasses.stream(), modifiedClasses.stream().filter( clazz -> !clazz.isAnnotationPresent(Route.class))) .filter(Component.class::isAssignableFrom) .forEach(clazz -> { Class<? extends Component> componentClass = (Class<? extends Component>) clazz; logger.debug("Removing route to {}", componentClass); routeConf.removeRoute(componentClass); }); Stream.concat(addedClasses.stream(), modifiedClasses.stream()) .distinct() .filter(Component.class::isAssignableFrom) .filter(clazz -> clazz.isAnnotationPresent(Route.class)) .forEach(clazz -> { Class<? extends Component> componentClass = (Class<? extends Component>) clazz; logger.debug( "Updating route {} to {}", componentClass .getAnnotation(Route.class).value(), clazz); routeConf.removeRoute(componentClass); routeConf.setAnnotatedRoute(componentClass); }); }); } protected  RouteUtil(); static List<Class<? extends RouterLayout>> getParentLayouts(
            Class<?> component, String path); static String getRoutePath(Class<?> component, Route route); static String getRouteAliasPath(Class<?> component,
            RouteAlias alias); static List<Class<? extends RouterLayout>> getParentLayoutsForNonRouteTarget(
            Class<?> navigationTarget); static Class<? extends RouterLayout> getTopParentLayout(
            final Class<?> component, final String path); static String resolve(Class<?> component, Route route); static void updateRouteRegistry(RouteRegistry registry,
            Set<Class<?>> addedClasses, Set<Class<?>> modifiedClasses,
            Set<Class<?>> deletedClasses);  }
@Test public void newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry() { @Route("a") class A extends Component { } ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(new MockVaadinServletService().getContext()); RouteUtil.updateRouteRegistry(registry, Collections.singleton(A.class), Collections.emptySet(), Collections.emptySet()); Assert.assertTrue(registry.getConfiguration().hasRoute("a")); }
@Test public void deletedRouteAnnotatedClass_updateRouteRegistry_routeIsRemovedFromRegistry() { @Route("a") class A extends Component { } ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(new MockVaadinServletService().getContext()); registry.setRoute("a", A.class, Collections.emptyList()); Assert.assertTrue(registry.getConfiguration().hasRoute("a")); RouteUtil.updateRouteRegistry(registry, Collections.emptySet(), Collections.emptySet(), Collections.singleton(A.class)); Assert.assertFalse(registry.getConfiguration().hasRoute("a")); }
@Test public void renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry() { @Route("aa") class A extends Component { } ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(new MockVaadinServletService().getContext()); registry.setRoute("a", A.class, Collections.emptyList()); Assert.assertTrue(registry.getConfiguration().hasRoute("a")); RouteUtil.updateRouteRegistry(registry, Collections.emptySet(), Collections.singleton(A.class), Collections.emptySet()); Assert.assertFalse(registry.getConfiguration().hasRoute("a")); Assert.assertTrue(registry.getConfiguration().hasRoute("aa")); }
@Test public void deannotatedRouteClass_updateRouteRegistry_routeIsRemovedFromRegistry() { class A extends Component { } ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(new MockVaadinServletService().getContext()); registry.setRoute("a", A.class, Collections.emptyList()); Assert.assertTrue(registry.getConfiguration().hasRoute("a")); RouteUtil.updateRouteRegistry(registry, Collections.emptySet(), Collections.singleton(A.class), Collections.emptySet()); Assert.assertFalse(registry.getConfiguration().hasRoute("a")); }