@@ -89,6 +89,13 @@ public void testSecondInterval() throws Exception {
8989 assertEquals (maybeNegate (sign , Duration .ofSeconds (randomSeconds ).plusMillis (randomMillis )), amount );
9090 }
9191
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+
9299 public void testYearToMonth () throws Exception {
93100 int randomYear = randomNonNegativeInt ();
94101 int randomMonth = randomInt (11 );
@@ -119,9 +126,12 @@ public void testDayToSecond() throws Exception {
119126 int randomHour = randomInt (23 );
120127 int randomMinute = randomInt (59 );
121128 int randomSecond = randomInt (59 );
122- int randomMilli = randomInt (999999999 );
123129
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 );
125135 TemporalAmount amount = parseInterval (EMPTY , value , INTERVAL_DAY_TO_SECOND );
126136 assertEquals (maybeNegate (sign , Duration .ofDays (randomDay ).plusHours (randomHour ).plusMinutes (randomMinute )
127137 .plusSeconds (randomSecond ).plusMillis (randomMilli )), amount );
@@ -139,9 +149,12 @@ public void testHourToSecond() throws Exception {
139149 int randomHour = randomNonNegativeInt ();
140150 int randomMinute = randomInt (59 );
141151 int randomSecond = randomInt (59 );
142- int randomMilli = randomInt (999999999 );
143152
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 );
145158 TemporalAmount amount = parseInterval (EMPTY , value , INTERVAL_HOUR_TO_SECOND );
146159 assertEquals (maybeNegate (sign ,
147160 Duration .ofHours (randomHour ).plusMinutes (randomMinute ).plusSeconds (randomSecond ).plusMillis (randomMilli )), amount );
@@ -150,9 +163,12 @@ public void testHourToSecond() throws Exception {
150163 public void testMinuteToSecond () throws Exception {
151164 int randomMinute = randomNonNegativeInt ();
152165 int randomSecond = randomInt (59 );
153- int randomMilli = randomInt (999999999 );
154166
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 );
156172 TemporalAmount amount = parseInterval (EMPTY , value , INTERVAL_MINUTE_TO_SECOND );
157173 assertEquals (maybeNegate (sign , Duration .ofMinutes (randomMinute ).plusSeconds (randomSecond ).plusMillis (randomMilli )), amount );
158174 }
@@ -187,6 +203,20 @@ public void testDayToMinuteTooBig() throws Exception {
187203 + "], expected a positive number up to [23]" , pe .getMessage ());
188204 }
189205
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+
190220 public void testExtraCharLeading () throws Exception {
191221 String value = "a123" ;
192222 ParsingException pe = expectThrows (ParsingException .class , () -> parseInterval (EMPTY , value , INTERVAL_YEAR ));
0 commit comments