@Test
    public void shouldCorrectlyInitializeTraversalParentCacheForNestedUnionOrStepsWithDifferentLabels() {
        // traversal
        final Traversal<?, ?> traversal = __.V().as("n").out().as("m").
                union(
                        __.or(
                                __.select("n").hasLabel("software"),
                                __.select("m").hasLabel("person")
                        ),
                        __.or(
                                __.select("n").hasLabel("person")
                        ),
                        __.or(
                                __.hasLabel("person").as("x").select("x")
                        )
                );

        // expected order of traversal parents
        final List<Traversal<?, ?>> collectedTraversalParents = Arrays.asList(
                __.or(
                        __.select("n").hasLabel("software"),
                        __.select("m").hasLabel("person")
                ),
                __.or(
                        __.select("n").hasLabel("person")
                ),
                __.or(
                        __.hasLabel("person").as("x").select("x")
                ),
                __.union(
                        __.or(
                                __.select("n").hasLabel("software"),
                                __.select("m").hasLabel("person")
                        ),
                        __.or(
                                __.select("n").hasLabel("person")
                        ),
                        __.or(
                                __.hasLabel("person").as("x").select("x")
                        )
                ));

        // cache entries
        final List<Pair<Boolean, Set<String>>> expectedTraversalParentCacheEntries = Arrays.asList(
                new Pair<>(false, new HashSet<>(Arrays.asList("n", "m"))),
                new Pair<>(false, new HashSet<>(Collections.singletonList("n"))),
                new Pair<>(false, new HashSet<>(Collections.singletonList("x"))),
                new Pair<>(false, new HashSet<>(Arrays.asList("n", "m", "x"))),
                new Pair<>(false, new HashSet<>(Arrays.asList("n", "m", "x"))) // last entry for empty step/root traversal parent
        );

        doTest(traversal, Optional.of(collectedTraversalParents), Optional.of(expectedTraversalParentCacheEntries));
    }
Testing whether the cache for the FilterRankingStrategy is correctly initialized,
which includes gathering/collecting the traversal parents and their children steps
in the correct deep first manner.
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategyCacheInitializationTest.java