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:
parent
0bc9bfbacb
commit
70d8fecc54
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue