11package org .baeldung .guava .collections ;
22
3+ import static org .hamcrest .Matchers .nullValue ;
4+ import static org .junit .Assert .assertThat ;
5+
36import java .util .Arrays ;
47import java .util .Collections ;
58import java .util .List ;
@@ -16,14 +19,20 @@ public class GuavaOrderingExamplesTest {
1619 public final void givenCollectionWithNulls_whenSortingWithNullsLast_thenNullsAreLast () {
1720 final List <Integer > nums = Arrays .asList (3 , 5 , 4 , null , 1 , 2 );
1821 Collections .sort (nums , Ordering .natural ().nullsLast ());
19- System . out . println (nums );
22+ assertThat ( nums . get (nums . size () - 1 ), nullValue () );
2023 }
2124
2225 @ Test
2326 public final void givenCollectionWithNulls_whenSortingWithNullsFirst_thenNullsAreFirst () {
2427 final List <Integer > nums = Arrays .asList (3 , 5 , 4 , null , 1 , 2 );
2528 Collections .sort (nums , Ordering .natural ().nullsFirst ());
26- System . out . println (nums );
29+ assertThat (nums . get ( 0 ), nullValue () );
2730 }
2831
32+ @ Test
33+ public final void whenCollectionIsSortedNullsLastReversed_thenNullAreFirst () {
34+ final List <Integer > nums = Arrays .asList (3 , 5 , 4 , null , 1 , 2 );
35+ Collections .sort (nums , Ordering .natural ().nullsLast ().reverse ());
36+ assertThat (nums .get (0 ), nullValue ());
37+ }
2938}
0 commit comments