@Test
    public void shouldHaveProperEdgeLegality() {
        GraphFilter graphFilter = new GraphFilter();
        assertFalse(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.BOTH, "likes"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.flatMap(v -> v.get().edges(Direction.OUT, "created")));  // lambdas can not be introspected
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH, "likes"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.<Vertex>identity().bothE());  // there are no strategies for __.
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH, "likes"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.<Vertex>bothE().has("weight", 32));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH, "likes"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.<Vertex>inE().has("weight", 32));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH, "likes"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.<Vertex>bothE().limit(0));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.outE());
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.<Vertex>outE().limit(10));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.<Vertex>outE("knows").limit(10));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "created"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.bothE("created"));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.BOTH, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH, "knows"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.outE("knows", "likes"));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH, "likes"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.BOTH, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "knows"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "likes"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "created"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.union(__.inE("bought"), __.outE("created"), __.bothE("knows", "likes")));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "likes"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "worksFor"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.union(__.outE("created"), __.bothE("knows", "likes")));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "likes"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "likes"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "worksFor"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.union(__.inE("bought").has("weight", 32), __.outE("created"), __.bothE("knows", "likes")));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "likes"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN, "bought"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "worksFor"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "likes"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.union(__.inE("bought").has("weight", 32), __.outE("created"), __.bothE("knows", "likes", "bought")));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "likes"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "blah"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "bought"));
        assertEquals(GraphFilter.Legal.NO, graphFilter.checkEdgeLegality(Direction.OUT, "worksFor"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "likes"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "knows"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.union(__.outE("created").limit(0), __.inE("created")));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.OUT, "created"));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH, "created"));
        //
        graphFilter = new GraphFilter();
        graphFilter.setEdgeFilter(__.union(__.outE(), __.inE().limit(0)));
        assertTrue(graphFilter.hasEdgeFilter());
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH));
        assertEquals(GraphFilter.Legal.YES, graphFilter.checkEdgeLegality(Direction.OUT, "created"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.IN, "created"));
        assertEquals(GraphFilter.Legal.MAYBE, graphFilter.checkEdgeLegality(Direction.BOTH, "created"));
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java