Polishing

This commit is contained in:
Juergen Hoeller
2017-02-16 15:57:52 +01:00
parent 427fd9b19a
commit dfa8a7c358
4 changed files with 45 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,9 +23,7 @@ import org.springframework.util.comparator.CompoundComparator;
import static org.junit.Assert.*;
/**
* Unit tests for {@link PropertyComparator}
*
* @see org.springframework.util.comparator.ComparatorTests
* Unit tests for {@link PropertyComparator}.
*
* @author Keith Donald
* @author Chris Beams
@@ -40,7 +38,7 @@ public class PropertyComparatorTests {
Dog dog2 = new Dog();
dog2.setNickName("biscy");
PropertyComparator c = new PropertyComparator("nickName", false, true);
PropertyComparator<Dog> c = new PropertyComparator<>("nickName", false, true);
assertTrue(c.compare(dog, dog2) > 0);
assertTrue(c.compare(dog, dog) == 0);
assertTrue(c.compare(dog2, dog) < 0);
@@ -50,15 +48,14 @@ public class PropertyComparatorTests {
public void testPropertyComparatorNulls() {
Dog dog = new Dog();
Dog dog2 = new Dog();
PropertyComparator c = new PropertyComparator("nickName", false, true);
PropertyComparator<Dog> c = new PropertyComparator<>("nickName", false, true);
assertTrue(c.compare(dog, dog2) == 0);
}
@SuppressWarnings("unchecked")
@Test
public void testCompoundComparator() {
CompoundComparator<Dog> c = new CompoundComparator<Dog>();
c.addComparator(new PropertyComparator("lastName", false, true));
CompoundComparator<Dog> c = new CompoundComparator<>();
c.addComparator(new PropertyComparator<>("lastName", false, true));
Dog dog1 = new Dog();
dog1.setFirstName("macy");
@@ -70,19 +67,19 @@ public class PropertyComparatorTests {
assertTrue(c.compare(dog1, dog2) == 0);
c.addComparator(new PropertyComparator("firstName", false, true));
c.addComparator(new PropertyComparator<>("firstName", false, true));
assertTrue(c.compare(dog1, dog2) > 0);
dog2.setLastName("konikk dog");
assertTrue(c.compare(dog2, dog1) > 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));
CompoundComparator<Dog> c = new CompoundComparator<>();
c.addComparator(new PropertyComparator<>("lastName", false, true));
c.addComparator(new PropertyComparator<>("firstName", false, true));
Dog dog1 = new Dog();
dog1.setFirstName("macy");
dog1.setLastName("grayspots");
@@ -97,7 +94,6 @@ public class PropertyComparatorTests {
}
@SuppressWarnings("unused")
private static class Dog implements Comparable<Object> {
private String nickName;
@@ -106,11 +102,6 @@ public class PropertyComparatorTests {
private String lastName;
@Override
public int compareTo(Object o) {
return nickName.compareTo(((Dog)o).nickName);
}
public String getNickName() {
return nickName;
}
@@ -134,6 +125,11 @@ public class PropertyComparatorTests {
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public int compareTo(Object o) {
return this.nickName.compareTo(((Dog) o).nickName);
}
}
}