/sigmah/src/test/java/org/sigmah/test/AssertUtils.java

http://sigma-h.googlecode.com/ · Java · 33 lines · 22 code · 7 blank · 4 comment · 3 complexity · bf8dd0765d818b90a783157d5f6dae28 MD5 · raw file

  1. /*
  2. * All Sigmah code is released under the GNU General Public License v3
  3. * See COPYRIGHT.txt and LICENSE.txt.
  4. */
  5. package org.sigmah.test;
  6. import java.util.Collection;
  7. import java.util.Comparator;
  8. import java.util.Iterator;
  9. public class AssertUtils {
  10. public static <T> void assertSorted(String name, Collection<T> collection,
  11. Comparator<T> comparator) {
  12. if (collection.size() <= 1) {
  13. return;
  14. }
  15. Iterator<T> it = collection.iterator();
  16. T last = it.next();
  17. while (it.hasNext()) {
  18. T next = it.next();
  19. if (comparator.compare(last, next) > 0) {
  20. throw new AssertionError("The collection '" + name + "' is not sorted, " +
  21. last.toString() + " > " + next.toString());
  22. }
  23. last = next;
  24. }
  25. }
  26. }