@@ -89,6 +89,13 @@ public void testSecondInterval() throws Exception {
89
89
assertEquals (maybeNegate (sign , Duration .ofSeconds (randomSeconds ).plusMillis (randomMillis )), amount );
90
90
}
91
91
92
+ public void testSecondNoMillisInterval () throws Exception {
93
+ int randomSeconds = randomNonNegativeInt ();
94
+ String value = format (Locale .ROOT , "%s%d" , sign , randomSeconds );
95
+ TemporalAmount amount = parseInterval (EMPTY , value , INTERVAL_SECOND );
96
+ assertEquals (maybeNegate (sign , Duration .ofSeconds (randomSeconds )), amount );
97
+ }
98
+
92
99
public void testYearToMonth () throws Exception {
93
100
int randomYear = randomNonNegativeInt ();
94
101
int randomMonth = randomInt (11 );
@@ -119,9 +126,12 @@ public void testDayToSecond() throws Exception {
119
126
int randomHour = randomInt (23 );
120
127
int randomMinute = randomInt (59 );
121
128
int randomSecond = randomInt (59 );
122
- int randomMilli = randomInt (999999999 );
123
129
124
- String value = format (Locale .ROOT , "%s%d %d:%d:%d.%d" , sign , randomDay , randomHour , randomMinute , randomSecond , randomMilli );
130
+ boolean withMillis = randomBoolean ();
131
+ int randomMilli = withMillis ? randomInt (999999999 ) : 0 ;
132
+ String millisString = withMillis ? "." + randomMilli : "" ;
133
+
134
+ String value = format (Locale .ROOT , "%s%d %d:%d:%d%s" , sign , randomDay , randomHour , randomMinute , randomSecond , millisString );
125
135
TemporalAmount amount = parseInterval (EMPTY , value , INTERVAL_DAY_TO_SECOND );
126
136
assertEquals (maybeNegate (sign , Duration .ofDays (randomDay ).plusHours (randomHour ).plusMinutes (randomMinute )
127
137
.plusSeconds (randomSecond ).plusMillis (randomMilli )), amount );
@@ -139,9 +149,12 @@ public void testHourToSecond() throws Exception {
139
149
int randomHour = randomNonNegativeInt ();
140
150
int randomMinute = randomInt (59 );
141
151
int randomSecond = randomInt (59 );
142
- int randomMilli = randomInt (999999999 );
143
152
144
- String value = format (Locale .ROOT , "%s%d:%d:%d.%d" , sign , randomHour , randomMinute , randomSecond , randomMilli );
153
+ boolean withMillis = randomBoolean ();
154
+ int randomMilli = withMillis ? randomInt (999999999 ) : 0 ;
155
+ String millisString = withMillis ? "." + randomMilli : "" ;
156
+
157
+ String value = format (Locale .ROOT , "%s%d:%d:%d%s" , sign , randomHour , randomMinute , randomSecond , millisString );
145
158
TemporalAmount amount = parseInterval (EMPTY , value , INTERVAL_HOUR_TO_SECOND );
146
159
assertEquals (maybeNegate (sign ,
147
160
Duration .ofHours (randomHour ).plusMinutes (randomMinute ).plusSeconds (randomSecond ).plusMillis (randomMilli )), amount );
@@ -150,9 +163,12 @@ public void testHourToSecond() throws Exception {
150
163
public void testMinuteToSecond () throws Exception {
151
164
int randomMinute = randomNonNegativeInt ();
152
165
int randomSecond = randomInt (59 );
153
- int randomMilli = randomInt (999999999 );
154
166
155
- String value = format (Locale .ROOT , "%s%d:%d.%d" , sign , randomMinute , randomSecond , randomMilli );
167
+ boolean withMillis = randomBoolean ();
168
+ int randomMilli = withMillis ? randomInt (999999999 ) : 0 ;
169
+ String millisString = withMillis ? "." + randomMilli : "" ;
170
+
171
+ String value = format (Locale .ROOT , "%s%d:%d%s" , sign , randomMinute , randomSecond , millisString );
156
172
TemporalAmount amount = parseInterval (EMPTY , value , INTERVAL_MINUTE_TO_SECOND );
157
173
assertEquals (maybeNegate (sign , Duration .ofMinutes (randomMinute ).plusSeconds (randomSecond ).plusMillis (randomMilli )), amount );
158
174
}
@@ -187,6 +203,20 @@ public void testDayToMinuteTooBig() throws Exception {
187
203
+ "], expected a positive number up to [23]" , pe .getMessage ());
188
204
}
189
205
206
+ public void testIncompleteYearToMonthInterval () throws Exception {
207
+ String value = "123-" ;
208
+ ParsingException pe = expectThrows (ParsingException .class , () -> parseInterval (EMPTY , value , INTERVAL_YEAR_TO_MONTH ));
209
+ assertEquals ("line -1:0: Invalid [INTERVAL YEAR TO MONTH] value [123-]: incorrect format, expecting [numeric]-[numeric]" ,
210
+ pe .getMessage ());
211
+ }
212
+
213
+ public void testIncompleteDayToHourInterval () throws Exception {
214
+ String value = "123 23:" ;
215
+ ParsingException pe = expectThrows (ParsingException .class , () -> parseInterval (EMPTY , value , INTERVAL_DAY_TO_HOUR ));
216
+ assertEquals ("line -1:0: Invalid [INTERVAL DAY TO HOUR] value [123 23:]: unexpected trailing characters found [:]" ,
217
+ pe .getMessage ());
218
+ }
219
+
190
220
public void testExtraCharLeading () throws Exception {
191
221
String value = "a123" ;
192
222
ParsingException pe = expectThrows (ParsingException .class , () -> parseInterval (EMPTY , value , INTERVAL_YEAR ));
0 commit comments