Use @ParameterizedTest to iterate over available locales

This commit is contained in:
Benedikt Ritter 2018-09-05 15:58:27 +02:00
parent bce28f99f3
commit 7e440785d9
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
2 changed files with 33 additions and 27 deletions

View File

@ -527,6 +527,11 @@
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>

View File

@ -16,8 +16,9 @@
*/ */
package org.apache.commons.lang3.time; package org.apache.commons.lang3.time;
import static org.junit.Assert.assertNotEquals; import org.junit.jupiter.api.Test;
import static org.junit.Assert.fail; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
import java.text.ParseException; import java.text.ParseException;
@ -25,39 +26,39 @@
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class FastDateParser_TimeZoneStrategyTest { class FastDateParser_TimeZoneStrategyTest {
@Test @ParameterizedTest
public void testTimeZoneStrategyPattern() { @MethodSource("java.util.Locale#getAvailableLocales")
for(final Locale locale : Locale.getAvailableLocales()) { void testTimeZoneStrategyPattern(final Locale locale) {
final FastDateParser parser = new FastDateParser("z", TimeZone.getDefault(), locale); final FastDateParser parser = new FastDateParser("z", TimeZone.getDefault(), locale);
final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings(); final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
for(final String[] zone : zones) { for (final String[] zone : zones) {
for(int t = 1; t<zone.length; ++t) { for (int t = 1; t < zone.length; ++t) {
final String tzDisplay = zone[t]; final String tzDisplay = zone[t];
if (tzDisplay == null) { if (tzDisplay == null) {
break; break;
} }
try { try {
parser.parse(tzDisplay); parser.parse(tzDisplay);
} catch(final Exception ex) { } catch (final Exception ex) {
fail("'" + tzDisplay + "'" fail("'" + tzDisplay + "'"
+ " Locale: '" + locale.getDisplayName() + "'" + " Locale: '" + locale.getDisplayName() + "'"
+ " TimeZone: " + zone[0] + " TimeZone: " + zone[0]
+ " offset: " + t + " offset: " + t
+ " defaultLocale: " + Locale.getDefault() + " defaultLocale: " + Locale.getDefault()
+ " defaultTimeZone: " + TimeZone.getDefault().getDisplayName() + " defaultTimeZone: " + TimeZone.getDefault().getDisplayName()
); );
}
} }
} }
} }
} }
@Test @Test
public void testLang1219() throws ParseException { void testLang1219() throws ParseException {
final FastDateParser parser = new FastDateParser("dd.MM.yyyy HH:mm:ss z", TimeZone.getDefault(), Locale.GERMAN); final FastDateParser parser = new FastDateParser("dd.MM.yyyy HH:mm:ss z", TimeZone.getDefault(), Locale.GERMAN);
final Date summer = parser.parse("26.10.2014 02:00:00 MESZ"); final Date summer = parser.parse("26.10.2014 02:00:00 MESZ");