16
16
17
17
package org .springframework .format .datetime .standard ;
18
18
19
- import org .junit .jupiter .api .extension .ExtensionContext ;
20
- import org .junit .jupiter .params .ParameterizedTest ;
21
- import org .junit .jupiter .params .provider .Arguments ;
22
- import org .junit .jupiter .params .provider .ArgumentsProvider ;
23
- import org .junit .jupiter .params .provider .ArgumentsSource ;
24
-
25
19
import java .text .ParseException ;
26
20
import java .time .Instant ;
27
21
import java .time .format .DateTimeFormatter ;
28
22
import java .util .Random ;
29
23
import java .util .stream .Stream ;
30
24
25
+ import org .junit .jupiter .api .DisplayName ;
26
+ import org .junit .jupiter .api .DisplayNameGeneration ;
27
+ import org .junit .jupiter .api .DisplayNameGenerator .ReplaceUnderscores ;
28
+ import org .junit .jupiter .api .extension .ExtensionContext ;
29
+ import org .junit .jupiter .params .ParameterizedTest ;
30
+ import org .junit .jupiter .params .provider .Arguments ;
31
+ import org .junit .jupiter .params .provider .ArgumentsProvider ;
32
+ import org .junit .jupiter .params .provider .ArgumentsSource ;
33
+
31
34
import static java .time .Instant .MAX ;
32
35
import static java .time .Instant .MIN ;
33
36
import static java .time .ZoneId .systemDefault ;
34
37
import static org .assertj .core .api .Assertions .assertThat ;
35
38
36
39
/**
40
+ * Unit tests for {@link InstantFormatter}.
41
+ *
37
42
* @author Andrei Nevedomskii
43
+ * @author Sam Brannen
44
+ * @since 5.1.12
38
45
*/
39
- @ SuppressWarnings ("ConstantConditions" )
46
+ @ DisplayName ("InstantFormatter unit tests" )
47
+ @ DisplayNameGeneration (ReplaceUnderscores .class )
40
48
class InstantFormatterTests {
41
49
42
50
private final InstantFormatter instantFormatter = new InstantFormatter ();
43
51
44
52
@ ParameterizedTest
45
53
@ ArgumentsSource (ISOSerializedInstantProvider .class )
46
- void should_parse_an_ISO_formatted_string_representation_of_an_instant (String input ) throws ParseException {
54
+ void should_parse_an_ISO_formatted_string_representation_of_an_Instant (String input ) throws ParseException {
47
55
Instant expected = DateTimeFormatter .ISO_INSTANT .parse (input , Instant ::from );
48
56
49
57
Instant actual = instantFormatter .parse (input , null );
@@ -53,7 +61,7 @@ void should_parse_an_ISO_formatted_string_representation_of_an_instant(String in
53
61
54
62
@ ParameterizedTest
55
63
@ ArgumentsSource (RFC1123SerializedInstantProvider .class )
56
- void should_parse_an_RFC1123_formatted_string_representation_of_an_instant (String input ) throws ParseException {
64
+ void should_parse_an_RFC1123_formatted_string_representation_of_an_Instant (String input ) throws ParseException {
57
65
Instant expected = DateTimeFormatter .RFC_1123_DATE_TIME .parse (input , Instant ::from );
58
66
59
67
Instant actual = instantFormatter .parse (input , null );
@@ -63,7 +71,7 @@ void should_parse_an_RFC1123_formatted_string_representation_of_an_instant(Strin
63
71
64
72
@ ParameterizedTest
65
73
@ ArgumentsSource (RandomInstantProvider .class )
66
- void should_serialize_an_instant_using_ISO_format_and_ignoring_locale (Instant input ) {
74
+ void should_serialize_an_Instant_using_ISO_format_and_ignoring_Locale (Instant input ) {
67
75
String expected = DateTimeFormatter .ISO_INSTANT .format (input );
68
76
69
77
String actual = instantFormatter .print (input , null );
@@ -97,7 +105,7 @@ private static class RandomInstantProvider implements ArgumentsProvider {
97
105
98
106
private static final long DATA_SET_SIZE = 10 ;
99
107
100
- static final Random RANDOM = new Random ();
108
+ private static final Random random = new Random ();
101
109
102
110
Stream <?> provideArguments () {
103
111
return randomInstantStream (MIN , MAX );
@@ -109,11 +117,9 @@ public final Stream<? extends Arguments> provideArguments(ExtensionContext conte
109
117
}
110
118
111
119
Stream <Instant > randomInstantStream (Instant min , Instant max ) {
112
- return Stream .concat (
113
- Stream .of (Instant .now ()), // make sure that the data set includes current instant
114
- RANDOM .longs (min .getEpochSecond (), max .getEpochSecond ())
115
- .mapToObj (Instant ::ofEpochSecond )
116
- );
120
+ return Stream .concat (Stream .of (Instant .now ()), // make sure that the data set includes current instant
121
+ random .longs (min .getEpochSecond (), max .getEpochSecond ()).mapToObj (Instant ::ofEpochSecond ));
117
122
}
118
123
}
119
- }
124
+
125
+ }
0 commit comments