Skip to content

Commit bfcaa94

Browse files
committed
Add org.apache.commons.lang3.time.FastDateParser_TimeZoneStrategyTest.testJava25DeprecatedZoneId(String)
1 parent 9167659 commit bfcaa94

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
*/
1717
package org.apache.commons.lang3.time;
1818

19+
import static org.junit.jupiter.api.Assertions.assertEquals;
1920
import static org.junit.jupiter.api.Assertions.assertNotEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2022
import static org.junit.jupiter.api.Assertions.fail;
2123
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2224
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2325

2426
import java.text.DateFormatSymbols;
2527
import java.text.ParseException;
28+
import java.time.ZoneId;
2629
import java.util.ArrayList;
2730
import java.util.Comparator;
2831
import java.util.Date;
@@ -41,6 +44,7 @@
4144
import org.junit.jupiter.api.Test;
4245
import org.junit.jupiter.params.ParameterizedTest;
4346
import org.junit.jupiter.params.provider.MethodSource;
47+
import org.junit.jupiter.params.provider.ValueSource;
4448
import org.junitpioneer.jupiter.DefaultLocale;
4549
import org.junitpioneer.jupiter.DefaultTimeZone;
4650
import org.junitpioneer.jupiter.ReadsDefaultLocale;
@@ -73,6 +77,24 @@ private String[][] getZoneStringsSorted(final Locale locale) {
7377
return ArraySorter.sort(DateFormatSymbols.getInstance(locale).getZoneStrings(), Comparator.comparing(array -> array[0]));
7478
}
7579

80+
/**
81+
* Tests that known short {@link ZoneId}s still parse since all short IDs are deprecated starting in Java 25, but are not removed.
82+
*
83+
* TODO: Why don't all short IDs parse, even on Java 8?
84+
*
85+
* @throws ParseException Thrown on test failure.
86+
*/
87+
@ParameterizedTest
88+
@ValueSource(strings = { "ACT", "CST" })
89+
void testJava25DeprecatedZoneId(final String shortId) throws ParseException {
90+
final FastDateParser parser = new FastDateParser("dd.MM.yyyy HH:mm:ss z", TimeZone.getTimeZone(shortId), Locale.getDefault());
91+
final Date date1 = parser.parse("26.10.2014 02:00:00 " + shortId);
92+
// 1) parsing returns a value and doesn't throw.
93+
assertNotNull(date1);
94+
// 2) Something reasonable, note that getYear() subtracts 1900.
95+
assertEquals(2014, date1.getYear() + 1900);
96+
}
97+
7698
@Test
7799
void testLang1219() throws ParseException {
78100
final FastDateParser parser = new FastDateParser("dd.MM.yyyy HH:mm:ss z", TimeZone.getDefault(), Locale.GERMAN);
@@ -86,7 +108,6 @@ void testLang1219() throws ParseException {
86108
void testTimeZoneStrategy_DateFormatSymbols(final Locale locale) {
87109
testTimeZoneStrategyPattern_DateFormatSymbols_getZoneStrings(locale);
88110
}
89-
90111
@ParameterizedTest
91112
@MethodSource("org.apache.commons.lang3.LocaleUtils#availableLocaleList()")
92113
void testTimeZoneStrategy_TimeZone(final Locale locale) {

0 commit comments

Comments
 (0)