@Test
    @LoadGraphWith(MODERN)
    public void g_V_coalesceXoutEXknowsX_outEXcreatedXX_otherV_path_byXnameX_byXlabelX() {
        final Traversal<Vertex, Path> traversal = get_g_V_coalesceXoutEXknowsX_outEXcreatedXX_otherV_path_byXnameX_byXlabelX();
        printTraversalForm(traversal);
        final Map<String, Integer> first = new HashMap<>();
        final Map<String, Integer> last = new HashMap<>();
        int counter = 0;
        while (traversal.hasNext()) {
            counter++;
            final Path path = traversal.next();
            first.compute(path.<String>get(0), (k, v) -> v != null ? v + 1 : 1);
            last.compute(path.<String>get(2), (k, v) -> v != null ? v + 1 : 1);
            assertEquals(3, path.size());
            assertTrue((path.<String>get(0).equals("marko") && path.<String>get(1).equals("knows") && path.<String>get(2).equals("vadas"))
                    || (path.<String>get(0).equals("marko") && path.<String>get(1).equals("knows") && path.<String>get(2).equals("josh"))
                    || (path.<String>get(0).equals("josh") && path.<String>get(1).equals("created") && path.<String>get(2).equals("lop"))
                    || (path.<String>get(0).equals("josh") && path.<String>get(1).equals("created") && path.<String>get(2).equals("ripple"))
                    || (path.<String>get(0).equals("peter") && path.<String>get(1).equals("created") && path.<String>get(2).equals("lop")));
        }
        assertEquals(5, counter);
        assertEquals(2, (int) first.get("marko"));
        assertEquals(2, (int) first.get("josh"));
        assertEquals(1, (int) first.get("peter"));
        assertEquals(1, (int) last.get("josh"));
        assertEquals(1, (int) last.get("vadas"));
        assertEquals(2, (int) last.get("lop"));
        assertEquals(1, (int) last.get("ripple"));
        assertFalse(traversal.hasNext());
    }
@author Daniel Kuppitz (http://gremlin.guru)
gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceTest.java