@Test
public void testTraverse() {

    graph.addVertex();
    graph.addVertex();
    graph.addVertex();
    graph.addVertex();
    graph.addVertex();
    graph.addVertex();
    graph.setVertexObject(5, new Vertex("end"));
    graph.addEdge(0, 1, null); // 0
    graph.addEdge(0, 2, null); // 1
    graph.addEdge(0, 3, null); // 2
    graph.addEdge(1, 4, null); // 3
    graph.addEdge(2, 4, null); // 4
    graph.addEdge(4, 5, null); // 5
    graph.addEdge(3, 5, null); // 6
    Traverser traverser = Mockito.mock(Traverser.class);
    // Stops  on 1, 2 and 3
    Mockito.when(traverser.traverse(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(TraverseResult.CONTINUE);
    Mockito.when(traverser.traverse(4, 3, 1)).thenReturn(TraverseResult.TERMINATE);
    Mockito.when(traverser.traverse(4, 4, 2)).thenReturn(TraverseResult.TERMINATE);
    Mockito.when(traverser.traverse(5, 6, 3)).thenReturn(TraverseResult.TERMINATE);
    boolean[] encountered = new boolean[graph.getVertexCount()];
    Arrays.fill(encountered, false);
    graph.traverse(5, traverser, encountered);
    // Only vertex 4 and 5 encontered
    assertArrayEquals(new boolean[] {false, false, false, false, true, true}, encountered);
    graph.traverse(4, traverser);
}