/sigmah/src/test/java/org/sigmah/test/AssertUtils.java
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 6package org.sigmah.test; 7 8import java.util.Collection; 9import java.util.Comparator; 10import java.util.Iterator; 11 12public class AssertUtils { 13 14 public static <T> void assertSorted(String name, Collection<T> collection, 15 Comparator<T> comparator) { 16 if (collection.size() <= 1) { 17 return; 18 } 19 20 Iterator<T> it = collection.iterator(); 21 T last = it.next(); 22 23 while (it.hasNext()) { 24 T next = it.next(); 25 if (comparator.compare(last, next) > 0) { 26 throw new AssertionError("The collection '" + name + "' is not sorted, " + 27 last.toString() + " > " + next.toString()); 28 } 29 last = next; 30 } 31 } 32 33}