11package org .baeldung .java8 ;
22
3+ import static org .hamcrest .Matchers .equalTo ;
4+
35import java .util .Collections ;
46import java .util .List ;
57
68import org .baeldung .java8 .entity .Human ;
9+ import org .junit .Assert ;
710import org .junit .Test ;
811
912import com .google .common .collect .Lists ;
13+ import com .google .common .primitives .Ints ;
1014
1115public class Java8SortUnitTest {
1216
@@ -16,7 +20,14 @@ public class Java8SortUnitTest {
1620 public final void whenSortingEntitiesByName_thenCorrectlySorted () {
1721 final List <Human > humans = Lists .newArrayList (new Human ("Sarah" , 10 ), new Human ("Jack" , 12 ));
1822 Collections .sort (humans , (final Human h1 , final Human h2 ) -> h1 .getName ().compareTo (h2 .getName ()));
19- // Assert.assertThat(actual, matcher);
23+ Assert .assertThat (humans .get (0 ), equalTo (new Human ("Jack" , 12 )));
24+ }
25+
26+ @ Test
27+ public final void whenSortingEntitiesByAge_thenCorrectlySorted () {
28+ final List <Human > humans = Lists .newArrayList (new Human ("Sarah" , 10 ), new Human ("Jack" , 12 ));
29+ Collections .sort (humans , (final Human h1 , final Human h2 ) -> Ints .compare (h1 .getAge (), h2 .getAge ()));
30+ Assert .assertThat (humans .get (0 ), equalTo (new Human ("Sarah" , 10 )));
2031 }
2132
2233}
0 commit comments