From 5f6b1a0420d0a95826ccd73e53a4840e9df70cee Mon Sep 17 00:00:00 2001 From: Marian Koncek Date: Tue, 4 Aug 2020 14:49:48 +0200 Subject: [PATCH] Remove usage of junit pioneer --- .../lang3/StringUtilsContainsTest.java | 5 ++-- .../lang3/time/DateFormatUtilsTest.java | 10 ++++--- .../commons/lang3/time/DateUtilsTest.java | 21 +++++++++---- .../lang3/time/FastDateFormatTest.java | 30 +++++++++++++------ .../lang3/time/FastDatePrinterTest.java | 14 +++++---- 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java index 4a0a4cc..3fd6d99 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Locale; import org.junit.jupiter.api.Test; -import org.junitpioneer.jupiter.DefaultLocale; /** * Unit tests {@link org.apache.commons.lang3.StringUtils} - Contains methods @@ -227,9 +226,10 @@ public class StringUtilsContainsTest { assertTrue(StringUtils.containsAny("abc", "d", "abc")); } - @DefaultLocale(language = "de", country = "DE") @Test public void testContainsIgnoreCase_LocaleIndependence() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("de", "DE")); final Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() }; final String[][] tdata = { { "i", "I" }, { "I", "i" }, { "\u03C2", "\u03C3" }, { "\u03A3", "\u03C2" }, @@ -248,6 +248,7 @@ public class StringUtilsContainsTest { Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1]); } } + Locale.setDefault(current_locale); } @Test diff --git a/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java index 31679de..20155e8 100644 --- a/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java @@ -30,8 +30,6 @@ import java.util.Locale; import java.util.TimeZone; import org.junit.jupiter.api.Test; -import org.junitpioneer.jupiter.DefaultLocale; -import org.junitpioneer.jupiter.DefaultTimeZone; /** * TestCase for DateFormatUtils. @@ -166,9 +164,10 @@ public class DateFormatUtilsTest { testUTC("09:11:12Z", DateFormatUtils.ISO_TIME_NO_T_TIME_ZONE_FORMAT.getPattern()); } - @DefaultLocale(language = "en") @Test public void testSMTP() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en")); TimeZone timeZone = TimeZone.getTimeZone("GMT-3"); Calendar june = createJuneTestDate(timeZone); @@ -179,6 +178,7 @@ public class DateFormatUtilsTest { june = createJuneTestDate(timeZone); assertFormats("Sun, 08 Jun 2003 10:11:12 +0000", DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern(), timeZone, june); + Locale.setDefault(current_locale); } @Test @@ -187,14 +187,16 @@ public class DateFormatUtilsTest { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.parse(date); } - @DefaultTimeZone("UTC") @Test public void testLang530() throws ParseException { + TimeZone current_time_zone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); final Date d = new Date(); final String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d); final Date d2 = DateUtils.parseDate(isoDateStr, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); // the format loses milliseconds so have to reintroduce them assertEquals(d.getTime(), d2.getTime() + d.getTime() % 1000, "Date not equal to itself ISO formatted and parsed"); + TimeZone.setDefault(current_time_zone); } /** diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java index 14dbf89..db0a51a 100644 --- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java @@ -39,7 +39,6 @@ import java.util.TimeZone; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junitpioneer.jupiter.DefaultLocale; /** * Unit tests {@link org.apache.commons.lang3.time.DateUtils}. @@ -1553,39 +1552,49 @@ public class DateUtilsTest { dateParser.parse("December 2, 2001")); } - @DefaultLocale(language = "en") @Test public void testLANG799_EN_OK() throws ParseException { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en")); DateUtils.parseDate("Wed, 09 Apr 2008 23:55:38 GMT", "EEE, dd MMM yyyy HH:mm:ss zzz"); DateUtils.parseDateStrictly("Wed, 09 Apr 2008 23:55:38 GMT", "EEE, dd MMM yyyy HH:mm:ss zzz"); + Locale.setDefault(current_locale); } // Parse German date with English Locale - @DefaultLocale(language = "en") @Test public void testLANG799_EN_FAIL() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en")); assertThrows(ParseException.class, () -> DateUtils.parseDate("Mi, 09 Apr 2008 23:55:38 GMT", "EEE, dd MMM yyyy HH:mm:ss zzz")); + Locale.setDefault(current_locale); } - @DefaultLocale(language = "de") @Test public void testLANG799_DE_OK() throws ParseException { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("de")); DateUtils.parseDate("Mi, 09 Apr 2008 23:55:38 GMT", "EEE, dd MMM yyyy HH:mm:ss zzz"); DateUtils.parseDateStrictly("Mi, 09 Apr 2008 23:55:38 GMT", "EEE, dd MMM yyyy HH:mm:ss zzz"); + Locale.setDefault(current_locale); } // Parse English date with German Locale - @DefaultLocale(language = "de") @Test public void testLANG799_DE_FAIL() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("de")); assertThrows(ParseException.class, () -> DateUtils.parseDate("Wed, 09 Apr 2008 23:55:38 GMT", "EEE, dd MMM yyyy HH:mm:ss zzz")); + Locale.setDefault(current_locale); } // Parse German date with English Locale, specifying German Locale override - @DefaultLocale(language = "en") @Test public void testLANG799_EN_WITH_DE_LOCALE() throws ParseException { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en")); DateUtils.parseDate("Mi, 09 Apr 2008 23:55:38 GMT", Locale.GERMAN, "EEE, dd MMM yyyy HH:mm:ss zzz"); + Locale.setDefault(current_locale); } /** diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java index 31c4ea8..f96da11 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java @@ -36,8 +36,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLongArray; import org.junit.jupiter.api.Test; -import org.junitpioneer.jupiter.DefaultLocale; -import org.junitpioneer.jupiter.DefaultTimeZone; /** * Unit tests {@link org.apache.commons.lang3.time.FastDateFormat}. @@ -70,11 +68,13 @@ public class FastDateFormatTest { assertEquals(TimeZone.getDefault(), format2.getTimeZone()); } - @DefaultLocale(language = "en", country = "US") - @DefaultTimeZone("America/New_York") @Test public void test_getInstance_String_TimeZone() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en", "US")); + TimeZone current_time_zone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getTimeZone("Atlantic/Reykjavik")); final FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); @@ -89,11 +89,14 @@ public class FastDateFormatTest { assertSame(format3, format4); assertNotSame(format3, format5); assertNotSame(format4, format6); + Locale.setDefault(current_locale); + TimeZone.setDefault(current_time_zone); } - @DefaultLocale(language = "en", country = "US") @Test public void test_getInstance_String_Locale() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en", "US")); final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); final FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); final FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); @@ -101,11 +104,13 @@ public class FastDateFormatTest { assertNotSame(format1, format2); assertSame(format1, format3); assertEquals(Locale.GERMANY, format1.getLocale()); + Locale.setDefault(current_locale); } - @DefaultLocale(language = "en", country = "US") @Test public void test_changeDefault_Locale_DateInstance() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en", "US")); final FastDateFormat format1 = FastDateFormat.getDateInstance(FastDateFormat.FULL, Locale.GERMANY); final FastDateFormat format2 = FastDateFormat.getDateInstance(FastDateFormat.FULL); Locale.setDefault(Locale.GERMANY); @@ -116,11 +121,13 @@ public class FastDateFormatTest { assertSame(Locale.GERMANY, format3.getLocale()); assertNotSame(format1, format2); assertNotSame(format2, format3); + Locale.setDefault(current_locale); } - @DefaultLocale(language = "en", country = "US") @Test public void test_changeDefault_Locale_DateTimeInstance() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en", "US")); final FastDateFormat format1 = FastDateFormat.getDateTimeInstance(FastDateFormat.FULL, FastDateFormat.FULL, Locale.GERMANY); final FastDateFormat format2 = FastDateFormat.getDateTimeInstance(FastDateFormat.FULL, FastDateFormat.FULL); Locale.setDefault(Locale.GERMANY); @@ -131,12 +138,15 @@ public class FastDateFormatTest { assertSame(Locale.GERMANY, format3.getLocale()); assertNotSame(format1, format2); assertNotSame(format2, format3); + Locale.setDefault(current_locale); } - @DefaultLocale(language = "en", country = "US") - @DefaultTimeZone("America/New_York") @Test public void test_getInstance_String_TimeZone_Locale() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en", "US")); + TimeZone current_time_zone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getTimeZone("Atlantic/Reykjavik"), Locale.GERMANY); final FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); @@ -150,6 +160,8 @@ public class FastDateFormatTest { assertEquals(Locale.GERMANY, format1.getLocale()); assertEquals(Locale.GERMANY, format2.getLocale()); assertEquals(Locale.GERMANY, format3.getLocale()); + Locale.setDefault(current_locale); + TimeZone.setDefault(current_time_zone); } @Test diff --git a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java index 096cbbb..32dcf6f 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java @@ -32,8 +32,6 @@ import java.util.TimeZone; import org.apache.commons.lang3.SerializationUtils; import org.junit.jupiter.api.Test; -import org.junitpioneer.jupiter.DefaultLocale; -import org.junitpioneer.jupiter.DefaultTimeZone; /** * Unit tests {@link org.apache.commons.lang3.time.FastDatePrinter}. @@ -75,10 +73,12 @@ public class FastDatePrinterTest { return new FastDatePrinter(format, timeZone, locale); } - @DefaultLocale(language = "en", country = "US") - @DefaultTimeZone("America/New_York") @Test public void testFormat() { + Locale current_locale = Locale.getDefault(); + Locale.setDefault(new Locale("en", "US")); + TimeZone current_time_zone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); final GregorianCalendar cal1 = new GregorianCalendar(2003, 0, 10, 15, 33, 20); final GregorianCalendar cal2 = new GregorianCalendar(2003, 6, 10, 9, 0, 0); final Date date1 = cal1.getTime(); @@ -121,6 +121,8 @@ public class FastDatePrinterTest { // SDF bug fix starting with Java 7 assertEquals(sdf.format(date1).replaceAll("2003 03 03 03", "2003 2003 03 2003"), fdf.format(date1)); assertEquals(sdf.format(date2).replaceAll("2003 03 03 03", "2003 2003 03 2003"), fdf.format(date2)); + Locale.setDefault(current_locale); + TimeZone.setDefault(current_time_zone); } /** @@ -259,9 +261,10 @@ public class FastDatePrinterTest { assertEquals(NEW_YORK, printer.getTimeZone()); } - @DefaultTimeZone("UTC") @Test public void testTimeZoneAsZ() { + TimeZone current_time_zone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); final Calendar c = Calendar.getInstance(FastTimeZone.getGmtTimeZone()); final FastDateFormat noColonFormat = FastDateFormat.getInstance("Z"); assertEquals("+0000", noColonFormat.format(c)); @@ -271,6 +274,7 @@ public class FastDatePrinterTest { final FastDateFormat colonFormat = FastDateFormat.getInstance("ZZZ"); assertEquals("+00:00", colonFormat.format(c)); + TimeZone.setDefault(current_time_zone); } private static Calendar initializeCalendar(final TimeZone tz) { -- 2.25.4