RouteUtil { public static List<Class<? extends RouterLayout>> getParentLayouts( Class<?> component, String path) { final List<Class<? extends RouterLayout>> list = new ArrayList<>(); Optional<Route> route = AnnotationReader.getAnnotationFor(component, Route.class); List<RouteAlias> routeAliases = AnnotationReader .getAnnotationsFor(component, RouteAlias.class); if (route.isPresent() && path.equals(getRoutePath(component, route.get())) && !route.get().layout().equals(UI.class)) { list.addAll(collectRouteParentLayouts(route.get().layout())); } else { Optional<RouteAlias> matchingRoute = getMatchingRouteAlias( component, path, routeAliases); if (matchingRoute.isPresent()) { list.addAll(collectRouteParentLayouts( matchingRoute.get().layout())); } } return list; } 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 expected_parent_layouts_are_found_for_route() { List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(BaseRouteWithParentPrefixAndRouteAlias.class, "parent"); Assert.assertThat( "Get parent layouts for route \"\" with parent prefix \"parent\" gave wrong result.", parentLayouts, IsIterableContainingInOrder .contains(new Class[] { RoutePrefixParent.class })); parentLayouts = RouteUtil.getParentLayouts(RootWithParents.class, ""); Assert.assertThat( "Expected to receive MiddleParent and Parent classes as parents.", parentLayouts, IsIterableContainingInOrder.contains( new Class[] { MiddleParent.class, Parent.class })); }
@Test public void expected_parent_layouts_are_found_for_route_alias() { List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(RouteAliasWithParentPrefix.class, "aliasparent/alias"); Assert.assertThat( "Get parent layouts for route \"\" with parent prefix \"parent\" gave wrong result.", parentLayouts, IsIterableContainingInOrder.contains( new Class[] { RouteAliasPrefixParent.class })); }
@Test public void absolute_route_gets_expected_parent_layouts() { List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(AbsoluteRoute.class, "single"); Assert.assertThat( "Get parent layouts for route \"\" with parent prefix \"parent\" gave wrong result.", parentLayouts, IsIterableContainingInOrder .contains(new Class[] { RoutePrefixParent.class })); parentLayouts = RouteUtil.getParentLayouts(AbsoluteCenterRoute.class, "absolute/child"); Assert.assertThat( "Expected to receive MiddleParent and Parent classes as parents.", parentLayouts, IsIterableContainingInOrder.contains(new Class[] { AbsoluteCenterParent.class, RoutePrefixParent.class })); }
@Test public void abolute_route_alias_gets_expected_parent_layouts() { List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(AbsoluteRoute.class, "alias"); Assert.assertThat( "Get parent layouts for route \"\" with parent prefix \"parent\" gave wrong result.", parentLayouts, IsIterableContainingInOrder .contains(new Class[] { RoutePrefixParent.class })); parentLayouts = RouteUtil.getParentLayouts(AbsoluteCenterRoute.class, "absolute/alias"); Assert.assertThat( "Expected to receive MiddleParent and Parent classes as parents.", parentLayouts, IsIterableContainingInOrder.contains(new Class[] { AbsoluteCenterParent.class, RoutePrefixParent.class })); }
@Test public void parent_layouts_resolve_correctly_for_route_parent() { List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(MultiTarget.class, ""); Assert.assertThat( "Get parent layouts for route \"\" gave wrong result.", parentLayouts, IsIterableContainingInOrder .contains(new Class[] { Parent.class })); parentLayouts = RouteUtil.getParentLayouts(MultiTarget.class, "alias"); Assert.assertThat( "Get parent layouts for routeAlias \"alias\" gave wrong result.", parentLayouts, IsIterableContainingInOrder.contains( new Class[] { MiddleParent.class, Parent.class })); parentLayouts = RouteUtil.getParentLayouts(SubLayout.class, "parent/sub"); Assert.assertThat( "Get parent layouts for route \"parent/sub\" with parent Route + ParentLayout gave wrong result.", parentLayouts, IsIterableContainingInOrder.contains(new Class[] { MultiTarget.class, RoutePrefixParent.class })); }