コード例 #1
0
  @Test
  public void testPropertyComparator() {
    Dog dog = new Dog();
    dog.setNickName("mace");

    Dog dog2 = new Dog();
    dog2.setNickName("biscy");

    PropertyComparator c = new PropertyComparator("nickName", false, true);
    assertTrue(c.compare(dog, dog2) > 0);
    assertTrue(c.compare(dog, dog) == 0);
    assertTrue(c.compare(dog2, dog) < 0);
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  @Test
  public void testCompoundComparatorInvert() {
    CompoundComparator<Dog> c = new CompoundComparator<Dog>();
    c.addComparator(new PropertyComparator("lastName", false, true));
    c.addComparator(new PropertyComparator("firstName", false, true));
    Dog dog1 = new Dog();
    dog1.setFirstName("macy");
    dog1.setLastName("grayspots");

    Dog dog2 = new Dog();
    dog2.setFirstName("biscuit");
    dog2.setLastName("grayspots");

    assertTrue(c.compare(dog1, dog2) > 0);
    c.invertOrder();
    assertTrue(c.compare(dog1, dog2) < 0);
  }