예제 #1
0
 @Test(groups = "ordering")
 public void testIsStrictlyOrdered() {
   assertFalse(
       byLengthOrdering.isStrictlyOrdered(
           Arrays.asList(
               hanSolo.getName(),
               princessLeia.getName(),
               lukeSkywalker.getName(),
               lukeSkywalker.getName())));
 }
예제 #2
0
 @Test(groups = "ordering")
 public void testNullsFirst() {
   assertEquals(
       byLengthOrdering
           .nullsFirst()
           .sortedCopy(
               Arrays.asList(
                   hanSolo.getName(), null, lukeSkywalker.getName(), null, princessLeia.getName()))
           .toString(),
       "[null, null, Han Solo, Princess Leia, Luke Skywalker]");
 }
예제 #3
0
 @Test(groups = "ordering")
 public void testAdHocOrdering() {
   Ordering<String> byLengthOrdering =
       new Ordering<String>() {
         public int compare(String left, String right) {
           return (left.length() - right.length());
         }
       };
   assertEquals(
       byLengthOrdering.max(hanSolo.getName(), lukeSkywalker.getName(), princessLeia.getName()),
       "Luke Skywalker");
 }
예제 #4
0
 public int compare(StarWarsCharacter o1, StarWarsCharacter o2) {
   return o1.getName().compareTo(o2.getName());
 }