public void testMultipleEdgeSimplestCase() {
    vertexes.add(vertex1);
    vertexes.add(vertex2);

    vertex1.addEdge(vertex2, vertex1);

    TopologicalSorter<DefaultVertex> sorter = new TopologicalSorter<DefaultVertex>(vertexes);

    List<DefaultVertex> result = sorter.sort();

    assertSame(vertex2, result.get(0));
    assertSame(vertex1, result.get(1));
  }
  public void testMinimalCycleReturned() {
    vertexes.add(vertex1);
    vertexes.add(vertex2);
    vertexes.add(vertex3);

    vertex1.addEdge(vertex2);
    vertex3.addEdge(vertex2);
    vertex2.addEdge(vertex3);

    TopologicalSorter<DefaultVertex> sorter = new TopologicalSorter<DefaultVertex>(vertexes);

    assertEquals("2, 3", sorter.findCycle().toString());
  }
  public void testPickThenCycle() {
    vertexes.add(vertex1);
    vertexes.add(vertex2);
    vertexes.add(vertex3);

    vertex3.addEdge(vertex2);
    vertex2.addEdge(vertex3);

    TopologicalSorter<DefaultVertex> sorter = new TopologicalSorter<DefaultVertex>(vertexes);

    sorter.setBreakOnCycle(true);
    sorter.sort();

    assertEquals("2, 3", sorter.findCycle().toString());
  }
  public void testTwoCycle() {
    vertexes.add(vertex1);
    vertexes.add(vertex2);

    vertex1.addEdge(vertex2);
    vertex2.addEdge(vertex1);

    TopologicalSorter<DefaultVertex> sorter = new TopologicalSorter<DefaultVertex>(vertexes);

    assertEquals("1, 2", sorter.findCycle().toString());

    List<DefaultVertex> result = sorter.sort();

    assertEquals(2, result.size());
  }