@@ -20,113 +20,89 @@ public class AssertJJava8Test {
2020 public void givenOptional_shouldAssert () throws Exception {
2121 final Optional <String > givenOptional = Optional .of ("something" );
2222
23- assertThat (givenOptional )
24- .isPresent ()
25- .hasValue ("something" );
23+ assertThat (givenOptional ).isPresent ().hasValue ("something" );
2624 }
2725
2826 @ Test
2927 public void givenPredicate_shouldAssert () throws Exception {
3028 final Predicate <String > predicate = s -> s .length () > 4 ;
3129
32- assertThat (predicate )
33- .accepts ("aaaaa" , "bbbbb" )
34- .rejects ("a" , "b" )
35- .acceptsAll (asList ("aaaaa" , "bbbbb" ))
36- .rejectsAll (asList ("a" , "b" ));
30+ assertThat (predicate ).accepts ("aaaaa" , "bbbbb" ).rejects ("a" , "b" ).acceptsAll (asList ("aaaaa" , "bbbbb" )).rejectsAll (asList ("a" , "b" ));
3731 }
3832
3933 @ Test
4034 public void givenLocalDate_shouldAssert () throws Exception {
4135 final LocalDate givenLocalDate = LocalDate .of (2016 , 7 , 8 );
4236 final LocalDate todayDate = LocalDate .now ();
4337
44- assertThat (givenLocalDate )
45- .isBefore (LocalDate .of (2020 , 7 , 8 ))
46- .isAfterOrEqualTo (LocalDate .of (1989 , 7 , 8 ));
38+ assertThat (givenLocalDate ).isBefore (LocalDate .of (2020 , 7 , 8 )).isAfterOrEqualTo (LocalDate .of (1989 , 7 , 8 ));
4739
48- assertThat (todayDate )
49- .isAfter (LocalDate .of (1989 , 7 , 8 ))
50- .isToday ();
40+ assertThat (todayDate ).isAfter (LocalDate .of (1989 , 7 , 8 )).isToday ();
5141 }
5242
5343 @ Test
5444 public void givenLocalDateTime_shouldAssert () throws Exception {
5545 final LocalDateTime givenLocalDate = LocalDateTime .of (2016 , 7 , 8 , 12 , 0 );
5646
57- assertThat (givenLocalDate )
58- .isBefore (LocalDateTime .of (2020 , 7 , 8 , 11 , 2 ));
47+ assertThat (givenLocalDate ).isBefore (LocalDateTime .of (2020 , 7 , 8 , 11 , 2 ));
5948 }
6049
6150 @ Test
6251 public void givenLocalTime_shouldAssert () throws Exception {
6352 final LocalTime givenLocalTime = LocalTime .of (12 , 15 );
6453
65- assertThat (givenLocalTime )
66- .isAfter (LocalTime .of (1 , 0 ))
67- .hasSameHourAs (LocalTime .of (12 , 0 ));
54+ assertThat (givenLocalTime ).isAfter (LocalTime .of (1 , 0 )).hasSameHourAs (LocalTime .of (12 , 0 ));
6855 }
6956
7057 @ Test
7158 public void givenList_shouldAssertFlatExtracting () throws Exception {
7259 final List <LocalDate > givenList = asList (ofYearDay (2016 , 5 ), ofYearDay (2015 , 6 ));
7360
74- assertThat (givenList )
75- .flatExtracting (LocalDate ::getYear )
76- .contains (2015 );
61+ assertThat (givenList ).flatExtracting (LocalDate ::getYear ).contains (2015 );
7762 }
7863
7964 @ Test
8065 public void givenList_shouldAssertFlatExtractingLeapYear () throws Exception {
8166 final List <LocalDate > givenList = asList (ofYearDay (2016 , 5 ), ofYearDay (2015 , 6 ));
8267
83- assertThat (givenList )
84- .flatExtracting (LocalDate ::isLeapYear )
85- .contains (true );
68+ assertThat (givenList ).flatExtracting (LocalDate ::isLeapYear ).contains (true );
8669 }
8770
8871 @ Test
8972 public void givenList_shouldAssertFlatExtractingClass () throws Exception {
9073 final List <LocalDate > givenList = asList (ofYearDay (2016 , 5 ), ofYearDay (2015 , 6 ));
9174
92- assertThat (givenList )
93- .flatExtracting (Object ::getClass )
94- .contains (LocalDate .class );
75+ assertThat (givenList ).flatExtracting (Object ::getClass ).contains (LocalDate .class );
9576 }
9677
9778 @ Test
9879 public void givenList_shouldAssertMultipleFlatExtracting () throws Exception {
9980 final List <LocalDate > givenList = asList (ofYearDay (2016 , 5 ), ofYearDay (2015 , 6 ));
10081
101- assertThat (givenList )
102- .flatExtracting (LocalDate ::getYear , LocalDate ::getDayOfMonth )
103- .contains (2015 , 6 );
82+ assertThat (givenList ).flatExtracting (LocalDate ::getYear , LocalDate ::getDayOfMonth ).contains (2015 , 6 );
10483 }
10584
10685 @ Test
10786 public void givenString_shouldSatisfy () throws Exception {
10887 final String givenString = "someString" ;
10988
110- assertThat (givenString )
111- .satisfies (s -> {
112- assertThat (s ).isNotEmpty ();
113- assertThat (s ).hasSize (10 );
114- });
89+ assertThat (givenString ).satisfies (s -> {
90+ assertThat (s ).isNotEmpty ();
91+ assertThat (s ).hasSize (10 );
92+ });
11593 }
11694
11795 @ Test
11896 public void givenString_shouldMatch () throws Exception {
11997 final String emptyString = "" ;
12098
121- assertThat (emptyString )
122- .matches (String ::isEmpty );
99+ assertThat (emptyString ).matches (String ::isEmpty );
123100 }
124101
125102 @ Test
126103 public void givenList_shouldHasOnlyOneElementSatisfying () throws Exception {
127104 final List <String > givenList = Arrays .asList ("" );
128105
129- assertThat (givenList )
130- .hasOnlyOneElementSatisfying (s -> assertThat (s ).isEmpty ());
106+ assertThat (givenList ).hasOnlyOneElementSatisfying (s -> assertThat (s ).isEmpty ());
131107 }
132108}
0 commit comments