@Test(groups = "ordering") public void testIsStrictlyOrdered() { assertFalse( byLengthOrdering.isStrictlyOrdered( Arrays.asList( hanSolo.getName(), princessLeia.getName(), lukeSkywalker.getName(), lukeSkywalker.getName()))); }
@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]"); }
@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"); }
public int compare(StarWarsCharacter o1, StarWarsCharacter o2) { return o1.getName().compareTo(o2.getName()); }