Comparator comparing (#1515)

* Initial commit for Comparator.comparing article.

* Changes in the code as per suggestions in review.

* Change in test names as per suggestions...

* Changes in tests names for nullFirst and nullLast cases

* clean up.
This commit is contained in:
Parth Joshi 2017-03-28 18:29:33 +05:30 committed by KevinGilmore
parent 0bc9bfbacb
commit 70d8fecc54
1 changed files with 12 additions and 1 deletions

View File

@ -76,6 +76,15 @@ public class Java8ComparatorTest {
// System.out.println(Arrays.toString(employees));
assertTrue(Arrays.equals(employees, sortedEmployeesByNameDesc));
}
@Test
public void whenReversed_thenSortedByNameDesc() {
Comparator<Employee> employeeNameComparator = Comparator.comparing(Employee::getName);
Comparator<Employee> employeeNameComparatorReversed = employeeNameComparator.reversed();
Arrays.sort(employees, employeeNameComparatorReversed);
// System.out.println(Arrays.toString(employees));
assertTrue(Arrays.equals(employees, sortedEmployeesByNameDesc));
}
@Test
public void whenComparingInt_thenSortedByAge() {
@ -153,4 +162,6 @@ public class Java8ComparatorTest {
assertTrue(Arrays.equals(someMoreEmployees, sortedEmployeesByNameAge));
}
}
}