### Question:
ComparatorChain implements Comparator<E>, Serializable { @Override public int compare(final E o1, final E o2) throws UnsupportedOperationException { if (isLocked == false) { checkChainIntegrity(); isLocked = true; } final Iterator<Comparator<E>> comparators = comparatorChain.iterator(); for (int comparatorIndex = 0; comparators.hasNext(); ++comparatorIndex) { final Comparator<? super E> comparator = comparators.next(); int retval = comparator.compare(o1,o2); if (retval != 0) { if (orderingBits.get(comparatorIndex) == true) { if (retval > 0) { retval = -1; } else { retval = 1; } } return retval; } } return 0; } ComparatorChain();  ComparatorChain(final Comparator<E> comparator);  ComparatorChain(final Comparator<E> comparator, final boolean reverse);  ComparatorChain(final List<Comparator<E>> list);  ComparatorChain(final List<Comparator<E>> list, final BitSet bits); void addComparator(final Comparator<E> comparator); void addComparator(final Comparator<E> comparator, final boolean reverse); void setComparator(final int index, final Comparator<E> comparator); void setComparator(final int index, final Comparator<E> comparator, final boolean reverse); void setForwardSort(final int index); void setReverseSort(final int index); int size(); boolean isLocked(); @Override int compare(final E o1, final E o2); @Override int hashCode(); @Override boolean equals(final Object object);  }### Answer:
@Test public void testBadNoopComparatorChain() { final ComparatorChain<Integer> chain = new ComparatorChain<Integer>(); final Integer i1 = Integer.valueOf(4); final Integer i2 = Integer.valueOf(6); try { chain.compare(i1,i2); fail("An exception should be thrown when a chain contains zero comparators."); } catch (final UnsupportedOperationException e) { } }
@Test public void testListComparatorChain() { final List<Comparator<Integer>> list = new LinkedList<Comparator<Integer>>(); list.add(new ComparableComparator<Integer>()); final ComparatorChain<Integer> chain = new ComparatorChain<Integer>(list); final Integer i1 = Integer.valueOf(4); final Integer i2 = Integer.valueOf(6); final int correctValue = i1.compareTo(i2); assertTrue("Comparison returns the right order", chain.compare(i1, i2) == correctValue); }
@Test public void testBadListComparatorChain() { final List<Comparator<Integer>> list = new LinkedList<Comparator<Integer>>(); final ComparatorChain<Integer> chain = new ComparatorChain<Integer>(list); final Integer i1 = Integer.valueOf(4); final Integer i2 = Integer.valueOf(6); try { chain.compare(i1, i2); fail("An exception should be thrown when a chain contains zero comparators."); } catch (final UnsupportedOperationException e) { } }