@Test
public void testDependentMapCircular() throws Exception {

    List<Table> list = new ArrayList<Table>(4);
    Table t1 = new Table("1");
    
    Table t2 = new Table("2");
    Table t3 = new Table("3");
    Table t4 = new Table("4");
    
    Table t5 = new Table("5");
    
    t4.addForeignKey(new ForeignKey("3","3"));
    t3.addForeignKey(new ForeignKey("2","2"));
    t4.addForeignKey(new ForeignKey("2","2"));
    
    list.add(t1);
    list.add(t2);
    list.add(t3);
    list.add(t4);
    list.add(t5);
    
    Map<Integer, Set<Table>> dependencyMap = new HashMap<Integer, Set<Table>>();
    
    list = Database.sortByForeignKeys(list, null, dependencyMap, null);
    
    assertTrue(dependencyMap.get(1).contains(t1));
    assertTrue(dependencyMap.get(2).contains(t2));
    assertTrue(dependencyMap.get(2).contains(t3));
    assertTrue(dependencyMap.get(2).contains(t4));
    assertTrue(dependencyMap.get(3).contains(t5));
}