private SimpleGraph<Integer, DefaultEdge> buildGraphForTestDisconnected(int size) {
    SimpleGraph<Integer, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);

    VertexFactory<Integer> vertexFactory = new IntegerVertexFactory();

    CompleteGraphGenerator<Integer, DefaultEdge> completeGraphGenerator =
        new CompleteGraphGenerator<>(size);
    // two complete graphs
    SimpleGraph<Integer, DefaultEdge> east = new SimpleGraph<>(DefaultEdge.class);
    completeGraphGenerator.generateGraph(east, vertexFactory, null);

    SimpleGraph<Integer, DefaultEdge> west = new SimpleGraph<>(DefaultEdge.class);
    completeGraphGenerator.generateGraph(west, vertexFactory, null);

    Graphs.addGraph(graph, east);
    Graphs.addGraph(graph, west);
    // connected by single edge
    graph.addEdge(size - 1, size);

    return graph;
  }
  /**
   * Testing a graph where the validator denies the request to go on an edge which cutting it makes
   * the graph disconnected
   */
  public void testDisconnected() {
    int cliqueSize = 5;
    // generate graph of two cliques connected by single edge
    SimpleGraph<Integer, DefaultEdge> graph = buildGraphForTestDisconnected(cliqueSize);
    for (int i = 0; i < graph.vertexSet().size(); i++) {
      KShortestPaths<Integer, DefaultEdge> ksp =
          new KShortestPaths<Integer, DefaultEdge>(
              graph,
              i,
              100,
              Integer.MAX_VALUE,
              new PathValidator<Integer, DefaultEdge>() {

                @Override
                public boolean isValidPath(
                    AbstractPathElement<Integer, DefaultEdge> prevPathElement, DefaultEdge edge) {
                  // accept all requests but the one to pass through the edge connecting
                  // the two cliques.
                  DefaultEdge connectingEdge = graph.getEdge(cliqueSize - 1, cliqueSize);
                  return connectingEdge != edge;
                }
              });

      for (int j = 0; j < graph.vertexSet().size(); j++) {
        if (j == i) {
          continue;
        }
        List<GraphPath<Integer, DefaultEdge>> paths = ksp.getPaths(j);
        if ((i < cliqueSize && j < cliqueSize) || (i >= cliqueSize && j >= cliqueSize)) {
          // within the clique - path should exist
          assertNotNull(paths);
          assertTrue(paths.size() > 0);
        } else {
          // else - should not
          assertNull(paths);
        }
      }
    }
  }