20
20
import java .time .Instant ;
21
21
import java .time .format .DateTimeFormatter ;
22
22
import java .time .temporal .ChronoUnit ;
23
+ import java .util .Locale ;
23
24
import java .util .Random ;
24
25
import java .util .stream .Stream ;
25
26
@@ -50,44 +51,39 @@ class InstantFormatterTests {
50
51
51
52
private final InstantFormatter instantFormatter = new InstantFormatter ();
52
53
54
+
53
55
@ ParameterizedTest
54
56
@ ArgumentsSource (ISOSerializedInstantProvider .class )
55
57
void should_parse_an_ISO_formatted_string_representation_of_an_Instant (String input ) throws ParseException {
56
58
Instant expected = DateTimeFormatter .ISO_INSTANT .parse (input , Instant ::from );
57
-
58
- Instant actual = instantFormatter .parse (input , null );
59
-
59
+ Instant actual = instantFormatter .parse (input , Locale .US );
60
60
assertThat (actual ).isEqualTo (expected );
61
61
}
62
62
63
63
@ ParameterizedTest
64
64
@ ArgumentsSource (RFC1123SerializedInstantProvider .class )
65
65
void should_parse_an_RFC1123_formatted_string_representation_of_an_Instant (String input ) throws ParseException {
66
66
Instant expected = DateTimeFormatter .RFC_1123_DATE_TIME .parse (input , Instant ::from );
67
-
68
- Instant actual = instantFormatter .parse (input , null );
69
-
67
+ Instant actual = instantFormatter .parse (input , Locale .US );
70
68
assertThat (actual ).isEqualTo (expected );
71
69
}
72
70
73
71
@ ParameterizedTest
74
72
@ ArgumentsSource (RandomInstantProvider .class )
75
73
void should_serialize_an_Instant_using_ISO_format_and_ignoring_Locale (Instant input ) {
76
74
String expected = DateTimeFormatter .ISO_INSTANT .format (input );
77
-
78
- String actual = instantFormatter .print (input , null );
79
-
75
+ String actual = instantFormatter .print (input , Locale .US );
80
76
assertThat (actual ).isEqualTo (expected );
81
77
}
82
78
83
79
@ ParameterizedTest
84
80
@ ArgumentsSource (RandomEpochMillisProvider .class )
85
81
void should_parse_into_an_Instant_from_epoch_milli (Instant input ) throws ParseException {
86
- Instant actual = instantFormatter .parse (Long .toString (input .toEpochMilli ()), null );
87
-
82
+ Instant actual = instantFormatter .parse (Long .toString (input .toEpochMilli ()), Locale .US );
88
83
assertThat (actual ).isEqualTo (input );
89
84
}
90
85
86
+
91
87
private static class RandomInstantProvider implements ArgumentsProvider {
92
88
93
89
private static final long DATA_SET_SIZE = 10 ;
@@ -109,6 +105,7 @@ Stream<Instant> randomInstantStream(Instant min, Instant max) {
109
105
}
110
106
}
111
107
108
+
112
109
private static class ISOSerializedInstantProvider extends RandomInstantProvider {
113
110
114
111
@ Override
@@ -117,6 +114,7 @@ Stream<?> provideArguments() {
117
114
}
118
115
}
119
116
117
+
120
118
private static class RFC1123SerializedInstantProvider extends RandomInstantProvider {
121
119
122
120
// RFC-1123 supports only 4-digit years
@@ -130,6 +128,8 @@ Stream<?> provideArguments() {
130
128
.map (DateTimeFormatter .RFC_1123_DATE_TIME .withZone (systemDefault ())::format );
131
129
}
132
130
}
131
+
132
+
133
133
private static final class RandomEpochMillisProvider implements ArgumentsProvider {
134
134
135
135
private static final long DATA_SET_SIZE = 10 ;
0 commit comments