### Question:
CollectionUtils { public static <T> boolean isSorted(Collection<T> collection, Comparator<T> comparator) { if (collection != null) { if (collection.isEmpty() || collection.size() == 1) { return true; } final Iterator<T> iterator = collection.iterator(); T current, previous = iterator.next(); while (iterator.hasNext()) { current = iterator.next(); if (comparator.compare(previous, current) > 0) { return false; } previous = current; } return true; } else { return false; } }  static boolean isSorted(Collection<T> collection, Comparator<T> comparator);  }### Answer:
@Test public void shouldReturnFalseWhenCheckingIfCollectionIsSortedAndGivenCollectionIsNull() throws Exception { assertFalse(CollectionUtils.isSorted(null, integerComparator)); }
@Test public void shouldReturnTrueWhenCheckingIfCollectionIsSortedAndGivenCollectionIsEmpty() throws Exception { assertTrue(CollectionUtils.isSorted(Collections.emptyList(), integerComparator)); }
@Test public void shouldReturnTrueWhenCheckingIfCollectionIsSortedAndGivenCollectionHasOneElement() throws Exception { final List<Integer> list = Arrays.asList(1); assertTrue(CollectionUtils.isSorted(list, integerComparator)); }
@Test public void shouldReturnTrueWhenCheckingIfCollectionIsSortedAndGivenCollectionIsSorted() throws Exception { final List<Integer> list = Arrays.asList(1, 2, 5, 8, 9); assertTrue(CollectionUtils.isSorted(list, integerComparator)); }
@Test public void shouldReturnFalseWhenCheckingIfCollectionIsSortedAndGivenCollectionIsNotSorted() throws Exception { final List<Integer> list = Arrays.asList(1, 5, 2, 8, 9); assertFalse(CollectionUtils.isSorted(list, integerComparator)); }