@Test
 public void testFailingSortingComplex() {
   List<LoadingOrder.Orderable> target = new ArrayList<LoadingOrder.Orderable>();
   target.add(createElement(LoadingOrder.after("2"), "1", "bad"));
   target.add(createElement(LoadingOrder.after("3"), "2", "bad"));
   target.add(createElement(LoadingOrder.after("1"), "3", "bad"));
   LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[target.size()]);
   checkSortingFailure(array);
 }
 @Test
 public void testComplexSorting2() {
   List<LoadingOrder.Orderable> target = new ArrayList<LoadingOrder.Orderable>();
   String idOne = "idOne";
   target.add(createElement(LoadingOrder.before(idOne), null, "2"));
   target.add(createElement(LoadingOrder.after(idOne), null, "4"));
   target.add(createElement(LoadingOrder.FIRST, null, "1"));
   target.add(createElement(LoadingOrder.ANY, idOne, "3"));
   target.add(createElement(LoadingOrder.ANY, null, "5"));
   target.add(createElement(LoadingOrder.LAST, null, "6"));
   LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[target.size()]);
   assertSequence(array, "123456");
 }
 @Test
 public void testFailingSortingBeforeFirst() {
   List<LoadingOrder.Orderable> target = new ArrayList<LoadingOrder.Orderable>();
   target.add(createElement(LoadingOrder.ANY, null, "good"));
   target.add(createElement(LoadingOrder.FIRST, "first", "bad"));
   target.add(createElement(LoadingOrder.LAST, null, "good"));
   target.add(createElement(LoadingOrder.before("first"), null, "bad"));
   LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[target.size()]);
   checkSortingFailure(array);
 }
 private static void checkSortingFailure(LoadingOrder.Orderable[] array) {
   try {
     LoadingOrder.sort(array);
     fail("Should have failed");
   } catch (SortingException e) {
     Element[] conflictingElements = e.getConflictingElements();
     assertEquals(2, conflictingElements.length);
     assertEquals("bad", ((MyElement) conflictingElements[0]).getID());
     assertEquals("bad", ((MyElement) conflictingElements[1]).getID());
   }
 }
 private static void assertSequence(LoadingOrder.Orderable[] array, String expected) {
   LoadingOrder.sort(array);
   StringBuffer sequence = buildSequence(array);
   assertEquals(expected, sequence.toString());
 }