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>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>

View File

@ -16,8 +16,9 @@
*/
package org.apache.commons.lang3.time;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.text.DateFormatSymbols;
import java.text.ParseException;
@ -25,24 +26,25 @@
import java.util.Locale;
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
public void testTimeZoneStrategyPattern() {
for(final Locale locale : Locale.getAvailableLocales()) {
@ParameterizedTest
@MethodSource("java.util.Locale#getAvailableLocales")
void testTimeZoneStrategyPattern(final Locale locale) {
final FastDateParser parser = new FastDateParser("z", TimeZone.getDefault(), locale);
final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
for(final String[] zone : zones) {
for(int t = 1; t<zone.length; ++t) {
for (final String[] zone : zones) {
for (int t = 1; t < zone.length; ++t) {
final String tzDisplay = zone[t];
if (tzDisplay == null) {
break;
}
try {
parser.parse(tzDisplay);
} catch(final Exception ex) {
} catch (final Exception ex) {
fail("'" + tzDisplay + "'"
+ " Locale: '" + locale.getDisplayName() + "'"
+ " TimeZone: " + zone[0]
@ -54,10 +56,9 @@ public void testTimeZoneStrategyPattern() {
}
}
}
}
@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 Date summer = parser.parse("26.10.2014 02:00:00 MESZ");