Update time tests to JUnit Jupiter
Upgrade the tests in the time package to use JUnit Jupiter as part of the effort to remove the dependency on the Vintage Engine. While most of these changes are drop-in replacements with no functional benefit, there are some non-obvious changes worth mentioning. Unlike org.junit.Test, org.junit.jupiter.api.Test does not have an "expected" argument. Instead, an explicit call to org.junit.jupiter.api.Assertions.assertThrows is used. JUnit Jupiter no longer has a concept of runners. Tests previously run with the org.junit.runners.Parameterized runner were rewritten to use @ParameterizedTest and a @MethodSource. JUnit Jupiter also no longer has the concept of Rules. Usages of the SystemDefaultsSwitch rule and its accompanying annotates were replaced with the @DefaultLocale and @DefaultTimezone annotations that Benedikt Ritter contributed to JUnit Pioneer, the semi-official JUnit extension project. It's also worth noting this is a minimal patch for migrating the package's tests to Jupiter. There are several tests that can be made more elegant with Jupiter's new features, but that work is left for subsequent patches.
This commit is contained in:
parent
94beded839
commit
ca2e59c513
6
pom.xml
6
pom.xml
|
@ -543,6 +543,12 @@
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit-pioneer</groupId>
|
||||||
|
<artifactId>junit-pioneer</artifactId>
|
||||||
|
<version>0.2.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-all</artifactId>
|
<artifactId>hamcrest-all</artifactId>
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -29,20 +29,15 @@ import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.apache.commons.lang3.test.SystemDefaults;
|
import org.junitpioneer.jupiter.DefaultLocale;
|
||||||
import org.junit.Rule;
|
import org.junitpioneer.jupiter.DefaultTimeZone;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestCase for DateFormatUtils.
|
* TestCase for DateFormatUtils.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation") // tests lots of deprecated items
|
@SuppressWarnings("deprecation") // tests lots of deprecated items
|
||||||
public class DateFormatUtilsTest {
|
public class DateFormatUtilsTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor() {
|
public void testConstructor() {
|
||||||
|
@ -171,7 +166,7 @@ public class DateFormatUtilsTest {
|
||||||
testUTC("09:11:12Z", DateFormatUtils.ISO_TIME_NO_T_TIME_ZONE_FORMAT.getPattern());
|
testUTC("09:11:12Z", DateFormatUtils.ISO_TIME_NO_T_TIME_ZONE_FORMAT.getPattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(locale="en")
|
@DefaultLocale(language = "en")
|
||||||
@Test
|
@Test
|
||||||
public void testSMTP() {
|
public void testSMTP() {
|
||||||
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
||||||
|
@ -192,14 +187,14 @@ public class DateFormatUtilsTest {
|
||||||
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.parse(date);
|
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.parse(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(timezone="UTC")
|
@DefaultTimeZone("UTC")
|
||||||
@Test
|
@Test
|
||||||
public void testLang530() throws ParseException {
|
public void testLang530() throws ParseException {
|
||||||
final Date d = new Date();
|
final Date d = new Date();
|
||||||
final String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d);
|
final String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d);
|
||||||
final Date d2 = DateUtils.parseDate(isoDateStr, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
|
final Date d2 = DateUtils.parseDate(isoDateStr, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
|
||||||
// the format loses milliseconds so have to reintroduce them
|
// the format loses milliseconds so have to reintroduce them
|
||||||
assertEquals("Date not equal to itself ISO formatted and parsed", d.getTime(), d2.getTime() + d.getTime() % 1000);
|
assertEquals(d.getTime(), d2.getTime() + d.getTime() % 1000, "Date not equal to itself ISO formatted and parsed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -218,29 +213,29 @@ public class DateFormatUtilsTest {
|
||||||
// Long.
|
// Long.
|
||||||
{
|
{
|
||||||
final String value = DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/Paris"));
|
final String value = DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/Paris"));
|
||||||
assertEquals("long", "2009-10-16T08:42:16+02:00", value);
|
assertEquals("2009-10-16T08:42:16+02:00", value, "long");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final String value = DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Asia/Kolkata"));
|
final String value = DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Asia/Kolkata"));
|
||||||
assertEquals("long", "2009-10-16T12:12:16+05:30", value);
|
assertEquals("2009-10-16T12:12:16+05:30", value, "long");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final String value = DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/London"));
|
final String value = DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/London"));
|
||||||
assertEquals("long", "2009-10-16T07:42:16+01:00", value);
|
assertEquals("2009-10-16T07:42:16+01:00", value, "long");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calendar.
|
// Calendar.
|
||||||
{
|
{
|
||||||
final String value = DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/Paris"));
|
final String value = DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/Paris"));
|
||||||
assertEquals("calendar", "2009-10-16T08:42:16+02:00", value);
|
assertEquals("2009-10-16T08:42:16+02:00", value, "calendar");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final String value = DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Asia/Kolkata"));
|
final String value = DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Asia/Kolkata"));
|
||||||
assertEquals("calendar", "2009-10-16T12:12:16+05:30", value);
|
assertEquals("2009-10-16T12:12:16+05:30", value, "calendar");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final String value = DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/London"));
|
final String value = DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/London"));
|
||||||
assertEquals("calendar", "2009-10-16T07:42:16+01:00", value);
|
assertEquals("2009-10-16T07:42:16+01:00", value, "calendar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class DateUtilsFragmentTest {
|
||||||
private Calendar aCalendar;
|
private Calendar aCalendar;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
aCalendar = Calendar.getInstance();
|
aCalendar = Calendar.getInstance();
|
||||||
aCalendar.set(2005, months, days, hours, minutes, seconds);
|
aCalendar.set(2005, months, days, hours, minutes, seconds);
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -58,7 +58,7 @@ public class DateUtilsRoundingTest {
|
||||||
FastDateFormat fdf = DateFormatUtils.ISO_DATETIME_FORMAT;
|
FastDateFormat fdf = DateFormatUtils.ISO_DATETIME_FORMAT;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);
|
dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);
|
||||||
|
@ -665,9 +665,9 @@ public class DateUtilsRoundingTest {
|
||||||
final Date nextTruncateDate = DateUtils.addMilliseconds(lastTruncateDate, 1);
|
final Date nextTruncateDate = DateUtils.addMilliseconds(lastTruncateDate, 1);
|
||||||
|
|
||||||
//Date-comparison
|
//Date-comparison
|
||||||
assertEquals("Truncating "+ fdf.format(truncatedDate) +" as Date with CalendarField-value "+ calendarField +" must return itself", truncatedDate, DateUtils.truncate(truncatedDate, calendarField));
|
assertEquals(truncatedDate, DateUtils.truncate(truncatedDate, calendarField), "Truncating "+ fdf.format(truncatedDate) +" as Date with CalendarField-value "+ calendarField +" must return itself");
|
||||||
assertEquals(truncatedDate, DateUtils.truncate(lastTruncateDate, calendarField));
|
assertEquals(truncatedDate, DateUtils.truncate(lastTruncateDate, calendarField));
|
||||||
assertFalse(fdf.format(lastTruncateDate) +" is not an extreme when truncating as Date with CalendarField-value "+ calendarField, truncatedDate.equals(DateUtils.truncate(nextTruncateDate, calendarField)));
|
assertFalse(truncatedDate.equals(DateUtils.truncate(nextTruncateDate, calendarField)), fdf.format(lastTruncateDate) +" is not an extreme when truncating as Date with CalendarField-value "+ calendarField);
|
||||||
|
|
||||||
//Calendar-initiations
|
//Calendar-initiations
|
||||||
Calendar truncatedCalendar, lastTruncateCalendar, nextTruncateCalendar;
|
Calendar truncatedCalendar, lastTruncateCalendar, nextTruncateCalendar;
|
||||||
|
@ -679,17 +679,17 @@ public class DateUtilsRoundingTest {
|
||||||
nextTruncateCalendar.setTime(nextTruncateDate);
|
nextTruncateCalendar.setTime(nextTruncateDate);
|
||||||
|
|
||||||
//Calendar-comparison
|
//Calendar-comparison
|
||||||
assertEquals("Truncating "+ fdf.format(truncatedCalendar) +" as Calendar with CalendarField-value "+ calendarField +" must return itself", truncatedCalendar, DateUtils.truncate(truncatedCalendar, calendarField));
|
assertEquals(truncatedCalendar, DateUtils.truncate(truncatedCalendar, calendarField), "Truncating "+ fdf.format(truncatedCalendar) +" as Calendar with CalendarField-value "+ calendarField +" must return itself");
|
||||||
assertEquals(truncatedCalendar, DateUtils.truncate(lastTruncateCalendar, calendarField));
|
assertEquals(truncatedCalendar, DateUtils.truncate(lastTruncateCalendar, calendarField));
|
||||||
assertFalse(fdf.format(lastTruncateCalendar) +" is not an extreme when truncating as Calendar with CalendarField-value "+ calendarField, truncatedCalendar.equals(DateUtils.truncate(nextTruncateCalendar, calendarField)));
|
assertFalse(truncatedCalendar.equals(DateUtils.truncate(nextTruncateCalendar, calendarField)), fdf.format(lastTruncateCalendar) +" is not an extreme when truncating as Calendar with CalendarField-value "+ calendarField);
|
||||||
|
|
||||||
//Object-comparison
|
//Object-comparison
|
||||||
assertEquals("Truncating "+ fdf.format(truncatedDate) +" as Date cast to Object with CalendarField-value "+ calendarField +" must return itself as Date", truncatedDate, DateUtils.truncate((Object) truncatedDate, calendarField));
|
assertEquals(truncatedDate, DateUtils.truncate((Object) truncatedDate, calendarField), "Truncating "+ fdf.format(truncatedDate) +" as Date cast to Object with CalendarField-value "+ calendarField +" must return itself as Date");
|
||||||
assertEquals(truncatedDate, DateUtils.truncate((Object) lastTruncateDate, calendarField));
|
assertEquals(truncatedDate, DateUtils.truncate((Object) lastTruncateDate, calendarField));
|
||||||
assertFalse(fdf.format(lastTruncateDate) +" is not an extreme when truncating as Date cast to Object with CalendarField-value "+ calendarField, truncatedDate.equals(DateUtils.truncate((Object) nextTruncateDate, calendarField)));
|
assertFalse(truncatedDate.equals(DateUtils.truncate((Object) nextTruncateDate, calendarField)), fdf.format(lastTruncateDate) +" is not an extreme when truncating as Date cast to Object with CalendarField-value "+ calendarField);
|
||||||
assertEquals("Truncating "+ fdf.format(truncatedCalendar) +" as Calendar cast to Object with CalendarField-value "+ calendarField +" must return itself as Date", truncatedDate, DateUtils.truncate((Object) truncatedCalendar, calendarField));
|
assertEquals(truncatedDate, DateUtils.truncate((Object) truncatedCalendar, calendarField), "Truncating "+ fdf.format(truncatedCalendar) +" as Calendar cast to Object with CalendarField-value "+ calendarField +" must return itself as Date");
|
||||||
assertEquals(truncatedDate, DateUtils.truncate((Object) lastTruncateCalendar, calendarField));
|
assertEquals(truncatedDate, DateUtils.truncate((Object) lastTruncateCalendar, calendarField));
|
||||||
assertFalse(fdf.format(lastTruncateCalendar) +" is not an extreme when truncating as Calendar cast to Object with CalendarField-value "+ calendarField, truncatedDate.equals(DateUtils.truncate((Object) nextTruncateCalendar, calendarField)));
|
assertFalse(truncatedDate.equals(DateUtils.truncate((Object) nextTruncateCalendar, calendarField)), fdf.format(lastTruncateCalendar) +" is not an extreme when truncating as Calendar cast to Object with CalendarField-value "+ calendarField);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -703,7 +703,7 @@ public class DateUtilsRoundingTest {
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
protected void roundToJanuaryFirst(final Date minDate, final Date maxDate, final int calendarField) {
|
protected void roundToJanuaryFirst(final Date minDate, final Date maxDate, final int calendarField) {
|
||||||
assertEquals("Rounding "+ fdf.format(januaryOneDate) +" as Date with CalendarField-value "+ calendarField +" must return itself", januaryOneDate, DateUtils.round(januaryOneDate, calendarField));
|
assertEquals(januaryOneDate, DateUtils.round(januaryOneDate, calendarField), "Rounding "+ fdf.format(januaryOneDate) +" as Date with CalendarField-value "+ calendarField +" must return itself");
|
||||||
assertEquals(januaryOneDate, DateUtils.round(minDate, calendarField));
|
assertEquals(januaryOneDate, DateUtils.round(minDate, calendarField));
|
||||||
assertEquals(januaryOneDate, DateUtils.round(maxDate, calendarField));
|
assertEquals(januaryOneDate, DateUtils.round(maxDate, calendarField));
|
||||||
|
|
||||||
|
@ -711,20 +711,20 @@ public class DateUtilsRoundingTest {
|
||||||
minCalendar.setTime(minDate);
|
minCalendar.setTime(minDate);
|
||||||
final Calendar maxCalendar = Calendar.getInstance();
|
final Calendar maxCalendar = Calendar.getInstance();
|
||||||
maxCalendar.setTime(maxDate);
|
maxCalendar.setTime(maxDate);
|
||||||
assertEquals("Rounding "+ fdf.format(januaryOneCalendar) +" as Date with CalendarField-value "+ calendarField +" must return itself", januaryOneCalendar, DateUtils.round(januaryOneCalendar, calendarField));
|
assertEquals(januaryOneCalendar, DateUtils.round(januaryOneCalendar, calendarField), "Rounding "+ fdf.format(januaryOneCalendar) +" as Date with CalendarField-value "+ calendarField +" must return itself");
|
||||||
assertEquals(januaryOneCalendar, DateUtils.round(minCalendar, calendarField));
|
assertEquals(januaryOneCalendar, DateUtils.round(minCalendar, calendarField));
|
||||||
assertEquals(januaryOneCalendar, DateUtils.round(maxCalendar, calendarField));
|
assertEquals(januaryOneCalendar, DateUtils.round(maxCalendar, calendarField));
|
||||||
|
|
||||||
final Date toPrevRoundDate = DateUtils.addMilliseconds(minDate, -1);
|
final Date toPrevRoundDate = DateUtils.addMilliseconds(minDate, -1);
|
||||||
final Date toNextRoundDate = DateUtils.addMilliseconds(maxDate, 1);
|
final Date toNextRoundDate = DateUtils.addMilliseconds(maxDate, 1);
|
||||||
assertFalse(fdf.format(minDate) +" is not an lower-extreme when rounding as Date with CalendarField-value "+ calendarField, januaryOneDate.equals(DateUtils.round(toPrevRoundDate, calendarField)));
|
assertFalse(januaryOneDate.equals(DateUtils.round(toPrevRoundDate, calendarField)), fdf.format(minDate) +" is not an lower-extreme when rounding as Date with CalendarField-value "+ calendarField);
|
||||||
assertFalse(fdf.format(maxDate) +" is not an upper-extreme when rounding as Date with CalendarField-value "+ calendarField, januaryOneDate.equals(DateUtils.round(toNextRoundDate, calendarField)));
|
assertFalse(januaryOneDate.equals(DateUtils.round(toNextRoundDate, calendarField)), fdf.format(maxDate) +" is not an upper-extreme when rounding as Date with CalendarField-value "+ calendarField);
|
||||||
|
|
||||||
final Calendar toPrevRoundCalendar = Calendar.getInstance();
|
final Calendar toPrevRoundCalendar = Calendar.getInstance();
|
||||||
toPrevRoundCalendar.setTime(toPrevRoundDate);
|
toPrevRoundCalendar.setTime(toPrevRoundDate);
|
||||||
final Calendar toNextRoundCalendar = Calendar.getInstance();
|
final Calendar toNextRoundCalendar = Calendar.getInstance();
|
||||||
toNextRoundCalendar.setTime(toNextRoundDate);
|
toNextRoundCalendar.setTime(toNextRoundDate);
|
||||||
assertFalse(fdf.format(minCalendar) +" is not an lower-extreme when rounding as Date with CalendarField-value "+ calendarField, januaryOneDate.equals(DateUtils.round(toPrevRoundDate, calendarField)));
|
assertFalse(januaryOneDate.equals(DateUtils.round(toPrevRoundDate, calendarField)), fdf.format(minCalendar) +" is not an lower-extreme when rounding as Date with CalendarField-value "+ calendarField);
|
||||||
assertFalse(fdf.format(maxCalendar) +" is not an upper-extreme when rounding as Date with CalendarField-value "+ calendarField, januaryOneDate.equals(DateUtils.round(toNextRoundDate, calendarField)));
|
assertFalse(januaryOneDate.equals(DateUtils.round(toNextRoundDate, calendarField)), fdf.format(maxCalendar) +" is not an upper-extreme when rounding as Date with CalendarField-value "+ calendarField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,18 +17,19 @@
|
||||||
|
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestCase for DurationFormatUtils.
|
* TestCase for DurationFormatUtils.
|
||||||
|
@ -156,9 +157,9 @@ public class DurationFormatUtilsTest {
|
||||||
assertEquals("1 day 1 hour 1 minute 1 second", text);
|
assertEquals("1 day 1 hour 1 minute 1 second", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testFormatNegativeDurationWords() throws Exception {
|
public void testFormatNegativeDurationWords() {
|
||||||
DurationFormatUtils.formatDurationWords(-5000, true, true);
|
assertThrows(IllegalArgumentException.class, () -> DurationFormatUtils.formatDurationWords(-5000, true, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -191,9 +192,9 @@ public class DurationFormatUtilsTest {
|
||||||
assertEquals("01:02:12.789", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("01:02:12.789", DurationFormatUtils.formatDurationHMS(time));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testFormatNegativeDurationHMS() throws Exception {
|
public void testFormatNegativeDurationHMS() {
|
||||||
DurationFormatUtils.formatDurationHMS(-5000);
|
assertThrows(IllegalArgumentException.class, () -> DurationFormatUtils.formatDurationHMS(-5000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -205,9 +206,9 @@ public class DurationFormatUtilsTest {
|
||||||
assertEquals("P0Y0M0DT0H1M15.321S", DurationFormatUtils.formatDurationISO(75321L));
|
assertEquals("P0Y0M0DT0H1M15.321S", DurationFormatUtils.formatDurationISO(75321L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testFormatNegativeDurationISO() throws Exception {
|
public void testFormatNegativeDurationISO() {
|
||||||
DurationFormatUtils.formatDurationISO(-5000);
|
assertThrows(IllegalArgumentException.class, () -> DurationFormatUtils.formatDurationISO(-5000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -248,9 +249,9 @@ public class DurationFormatUtilsTest {
|
||||||
assertEquals("0 0 " + days, DurationFormatUtils.formatDuration(duration, "y M d"));
|
assertEquals("0 0 " + days, DurationFormatUtils.formatDuration(duration, "y M d"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testFormatNegativeDuration() throws Exception {
|
public void testFormatNegativeDuration() {
|
||||||
DurationFormatUtils.formatDuration(-5000, "S", true);
|
assertThrows(IllegalArgumentException.class, () -> DurationFormatUtils.formatDuration(-5000, "S", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@ -282,9 +283,9 @@ public class DurationFormatUtilsTest {
|
||||||
// assertEquals("P1Y2M3DT10H30M", text);
|
// assertEquals("P1Y2M3DT10H30M", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testFormatPeriodISOStartGreaterEnd() throws Exception {
|
public void testFormatPeriodISOStartGreaterEnd() {
|
||||||
DurationFormatUtils.formatPeriodISO(5000, 2000);
|
assertThrows(IllegalArgumentException.class, () -> DurationFormatUtils.formatPeriodISO(5000, 2000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -348,9 +349,9 @@ public class DurationFormatUtilsTest {
|
||||||
assertEquals("048", DurationFormatUtils.formatPeriod(time1970, time, "MMM"));
|
assertEquals("048", DurationFormatUtils.formatPeriod(time1970, time, "MMM"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testFormatPeriodeStartGreaterEnd() throws Exception {
|
public void testFormatPeriodeStartGreaterEnd() {
|
||||||
DurationFormatUtils.formatPeriod(5000, 2500, "yy/MM");
|
assertThrows(IllegalArgumentException.class, () -> DurationFormatUtils.formatPeriod(5000, 2500, "yy/MM"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -396,13 +397,13 @@ public class DurationFormatUtilsTest {
|
||||||
|
|
||||||
// test failures in equals
|
// test failures in equals
|
||||||
final DurationFormatUtils.Token token = new DurationFormatUtils.Token(DurationFormatUtils.y, 4);
|
final DurationFormatUtils.Token token = new DurationFormatUtils.Token(DurationFormatUtils.y, 4);
|
||||||
assertFalse("Token equal to non-Token class. ", token.equals(new Object()));
|
assertFalse(token.equals(new Object()), "Token equal to non-Token class. ");
|
||||||
assertFalse("Token equal to Token with wrong value class. ", token.equals(new DurationFormatUtils.Token(
|
assertFalse(token.equals(new DurationFormatUtils.Token(new Object())),
|
||||||
new Object())));
|
"Token equal to Token with wrong value class. ");
|
||||||
assertFalse("Token equal to Token with different count. ", token.equals(new DurationFormatUtils.Token(
|
assertFalse(token.equals(new DurationFormatUtils.Token(DurationFormatUtils.y, 1)),
|
||||||
DurationFormatUtils.y, 1)));
|
"Token equal to Token with different count. ");
|
||||||
final DurationFormatUtils.Token numToken = new DurationFormatUtils.Token(Integer.valueOf(1), 4);
|
final DurationFormatUtils.Token numToken = new DurationFormatUtils.Token(Integer.valueOf(1), 4);
|
||||||
assertTrue("Token with Number value not equal to itself. ", numToken.equals(numToken));
|
assertTrue(numToken.equals(numToken), "Token with Number value not equal to itself. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -575,9 +576,9 @@ public class DurationFormatUtilsTest {
|
||||||
//bruteForce(1996, 1, 29, "M", Calendar.MONTH); // this will fail
|
//bruteForce(1996, 1, 29, "M", Calendar.MONTH); // this will fail
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testLANG981() { // unmatched quote char in lexx
|
public void testLANG981() { // unmatched quote char in lexx
|
||||||
DurationFormatUtils.lexx("'yMdHms''S");
|
assertThrows(IllegalArgumentException.class, () -> DurationFormatUtils.lexx("'yMdHms''S"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int FOUR_YEARS = 365 * 3 + 366;
|
private static final int FOUR_YEARS = 365 * 3 + 366;
|
||||||
|
@ -624,7 +625,7 @@ public class DurationFormatUtilsTest {
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
} else {
|
} else {
|
||||||
assertEquals(message, expected, result);
|
assertEquals(expected, result, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.text.FieldPosition;
|
import java.text.FieldPosition;
|
||||||
import java.text.Format;
|
import java.text.Format;
|
||||||
|
@ -36,10 +36,9 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLongArray;
|
import java.util.concurrent.atomic.AtomicLongArray;
|
||||||
|
|
||||||
import org.apache.commons.lang3.test.SystemDefaults;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
import org.junitpioneer.jupiter.DefaultLocale;
|
||||||
import org.junit.Rule;
|
import org.junitpioneer.jupiter.DefaultTimeZone;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.time.FastDateFormat}.
|
* Unit tests {@link org.apache.commons.lang3.time.FastDateFormat}.
|
||||||
|
@ -47,10 +46,6 @@ import org.junit.Test;
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class FastDateFormatTest {
|
public class FastDateFormatTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only the cache methods need to be tested here.
|
* Only the cache methods need to be tested here.
|
||||||
* The print methods are tested by {@link FastDateFormat_PrinterTest}
|
* The print methods are tested by {@link FastDateFormat_PrinterTest}
|
||||||
|
@ -76,7 +71,8 @@ public class FastDateFormatTest {
|
||||||
assertEquals(TimeZone.getDefault(), format2.getTimeZone());
|
assertEquals(TimeZone.getDefault(), format2.getTimeZone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(timezone="America/New_York", locale="en_US")
|
@DefaultLocale(language = "en", country = "US")
|
||||||
|
@DefaultTimeZone("America/New_York")
|
||||||
@Test
|
@Test
|
||||||
public void test_getInstance_String_TimeZone() {
|
public void test_getInstance_String_TimeZone() {
|
||||||
|
|
||||||
|
@ -96,7 +92,7 @@ public class FastDateFormatTest {
|
||||||
assertNotSame(format4, format6);
|
assertNotSame(format4, format6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(locale="en_US")
|
@DefaultLocale(language = "en", country = "US")
|
||||||
@Test
|
@Test
|
||||||
public void test_getInstance_String_Locale() {
|
public void test_getInstance_String_Locale() {
|
||||||
final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY);
|
final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY);
|
||||||
|
@ -108,7 +104,7 @@ public class FastDateFormatTest {
|
||||||
assertEquals(Locale.GERMANY, format1.getLocale());
|
assertEquals(Locale.GERMANY, format1.getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(locale="en_US")
|
@DefaultLocale(language = "en", country = "US")
|
||||||
@Test
|
@Test
|
||||||
public void test_changeDefault_Locale_DateInstance() {
|
public void test_changeDefault_Locale_DateInstance() {
|
||||||
final FastDateFormat format1 = FastDateFormat.getDateInstance(FastDateFormat.FULL, Locale.GERMANY);
|
final FastDateFormat format1 = FastDateFormat.getDateInstance(FastDateFormat.FULL, Locale.GERMANY);
|
||||||
|
@ -123,7 +119,7 @@ public class FastDateFormatTest {
|
||||||
assertNotSame(format2, format3);
|
assertNotSame(format2, format3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(locale="en_US")
|
@DefaultLocale(language = "en", country = "US")
|
||||||
@Test
|
@Test
|
||||||
public void test_changeDefault_Locale_DateTimeInstance() {
|
public void test_changeDefault_Locale_DateTimeInstance() {
|
||||||
final FastDateFormat format1 = FastDateFormat.getDateTimeInstance(FastDateFormat.FULL, FastDateFormat.FULL, Locale.GERMANY);
|
final FastDateFormat format1 = FastDateFormat.getDateTimeInstance(FastDateFormat.FULL, FastDateFormat.FULL, Locale.GERMANY);
|
||||||
|
@ -138,7 +134,8 @@ public class FastDateFormatTest {
|
||||||
assertNotSame(format2, format3);
|
assertNotSame(format2, format3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(locale="en_US", timezone="America/New_York")
|
@DefaultLocale(language = "en", country = "US")
|
||||||
|
@DefaultTimeZone("America/New_York")
|
||||||
@Test
|
@Test
|
||||||
public void test_getInstance_String_TimeZone_Locale() {
|
public void test_getInstance_String_TimeZone_Locale() {
|
||||||
final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy",
|
final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy",
|
||||||
|
|
|
@ -16,140 +16,131 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare FastDateParser with SimpleDateFormat
|
* Compare FastDateParser with SimpleDateFormat
|
||||||
*/
|
*/
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
public class FastDateParserSDFTest {
|
public class FastDateParserSDFTest {
|
||||||
|
|
||||||
@Parameters(name= "{index}: {0} {1} {2}")
|
public static Stream<Arguments> data() {
|
||||||
public static Collection<Object[]> data() {
|
return Stream.of(
|
||||||
return Arrays.asList(new Object [][]{
|
|
||||||
// General Time zone tests
|
// General Time zone tests
|
||||||
{"z yyyy", "GMT 2010", Locale.UK, true}, // no offset specified, but this is allowed as a TimeZone name
|
Arguments.of("z yyyy", "GMT 2010", Locale.UK, true), // no offset specified, but this is allowed as a TimeZone name
|
||||||
{"z yyyy", "GMT-123 2010", Locale.UK, false},
|
Arguments.of("z yyyy", "GMT-123 2010", Locale.UK, false),
|
||||||
{"z yyyy", "GMT-1234 2010", Locale.UK, false},
|
Arguments.of("z yyyy", "GMT-1234 2010", Locale.UK, false),
|
||||||
{"z yyyy", "GMT-12:34 2010", Locale.UK, true},
|
Arguments.of("z yyyy", "GMT-12:34 2010", Locale.UK, true),
|
||||||
{"z yyyy", "GMT-1:23 2010", Locale.UK, true},
|
Arguments.of("z yyyy", "GMT-1:23 2010", Locale.UK, true),
|
||||||
// RFC 822 tests
|
// RFC 822 tests
|
||||||
{"z yyyy", "-1234 2010", Locale.UK, true},
|
Arguments.of("z yyyy", "-1234 2010", Locale.UK, true),
|
||||||
{"z yyyy", "-12:34 2010", Locale.UK, false},
|
Arguments.of("z yyyy", "-12:34 2010", Locale.UK, false),
|
||||||
{"z yyyy", "-123 2010", Locale.UK, false},
|
Arguments.of("z yyyy", "-123 2010", Locale.UK, false),
|
||||||
// year tests
|
// year tests
|
||||||
{ "MM/dd/yyyy", "01/11/12", Locale.UK, true},
|
Arguments.of( "MM/dd/yyyy", "01/11/12", Locale.UK, true),
|
||||||
{ "MM/dd/yy", "01/11/12", Locale.UK, true},
|
Arguments.of( "MM/dd/yy", "01/11/12", Locale.UK, true),
|
||||||
|
|
||||||
// LANG-1089
|
// LANG-1089
|
||||||
{ "HH", "00", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "00", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "00", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "00", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "00", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "00", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "00", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "00", Locale.UK, true), // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
|
|
||||||
{ "HH", "01", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "01", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "01", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "01", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "01", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "01", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "01", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "01", Locale.UK, true), // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
|
|
||||||
{ "HH", "11", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "11", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "11", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "11", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "11", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "11", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "11", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "11", Locale.UK, true), // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
|
|
||||||
{ "HH", "12", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "12", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "12", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "12", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "12", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "12", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "12", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "12", Locale.UK, true), // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
|
|
||||||
{ "HH", "13", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "13", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "13", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "13", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "13", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "13", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "13", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "13", Locale.UK, true), // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
|
|
||||||
{ "HH", "23", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "23", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "23", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "23", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "23", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "23", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "23", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "23", Locale.UK, true), // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
|
|
||||||
{ "HH", "24", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "24", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "24", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "24", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "24", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "24", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "24", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "24", Locale.UK, true), // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
|
|
||||||
{ "HH", "25", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "25", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "25", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "25", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "25", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "25", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "25", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "25", Locale.UK, true), // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
|
|
||||||
{ "HH", "48", Locale.UK, true}, // Hour in day (0-23)
|
Arguments.of( "HH", "48", Locale.UK, true), // Hour in day (0-23)
|
||||||
{ "KK", "48", Locale.UK, true}, // Hour in am/pm (0-11)
|
Arguments.of( "KK", "48", Locale.UK, true), // Hour in am/pm (0-11)
|
||||||
{ "hh", "48", Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
Arguments.of( "hh", "48", Locale.UK, true), // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
|
||||||
{ "kk", "48", Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
|
Arguments.of( "kk", "48", Locale.UK, true) // Hour in day (1-24), i.e. midnight is 24, not 0
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String format;
|
private static final TimeZone timeZone = TimeZone.getDefault();
|
||||||
private final String input;
|
|
||||||
private final Locale locale;
|
|
||||||
private final boolean valid;
|
|
||||||
private final TimeZone timeZone = TimeZone.getDefault();
|
|
||||||
|
|
||||||
public FastDateParserSDFTest(final String format, final String input, final Locale locale, final boolean valid) {
|
@ParameterizedTest
|
||||||
this.format = format;
|
@MethodSource("data")
|
||||||
this.input = input;
|
public void testOriginal(final String format, final String input, final Locale locale, final boolean valid) {
|
||||||
this.locale = locale;
|
checkParse(input, format, locale, valid);
|
||||||
this.valid = valid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testOriginal() throws Exception {
|
@MethodSource("data")
|
||||||
checkParse(input);
|
public void testOriginalPP(final String format, final String input, final Locale locale, final boolean valid) {
|
||||||
|
checkParsePosition(input, format, locale, valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testOriginalPP() throws Exception {
|
@MethodSource("data")
|
||||||
checkParsePosition(input);
|
public void testUpperCase(final String format, final String input, final Locale locale, final boolean valid) {
|
||||||
|
checkParse(input.toUpperCase(locale), format, locale, valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testUpperCase() throws Exception {
|
@MethodSource("data")
|
||||||
checkParse(input.toUpperCase(locale));
|
public void testUpperCasePP(final String format, final String input, final Locale locale, final boolean valid) {
|
||||||
|
checkParsePosition(input.toUpperCase(locale), format, locale, valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testUpperCasePP() throws Exception {
|
@MethodSource("data")
|
||||||
checkParsePosition(input.toUpperCase(locale));
|
public void testLowerCase(final String format, final String input, final Locale locale, final boolean valid) {
|
||||||
|
checkParse(input.toLowerCase(locale), format, locale, valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testLowerCase() throws Exception {
|
@MethodSource("data")
|
||||||
checkParse(input.toLowerCase(locale));
|
public void testLowerCasePP(final String format, final String input, final Locale locale, final boolean valid) {
|
||||||
|
checkParsePosition(input.toLowerCase(locale), format, locale, valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private void checkParse(final String formattedDate, String format, Locale locale, boolean valid) {
|
||||||
public void testLowerCasePP() throws Exception {
|
|
||||||
checkParsePosition(input.toLowerCase(locale));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkParse(final String formattedDate) {
|
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
|
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
|
||||||
sdf.setTimeZone(timeZone);
|
sdf.setTimeZone(timeZone);
|
||||||
final DateParser fdf = new FastDateParser(format, timeZone, locale);
|
final DateParser fdf = new FastDateParser(format, timeZone, locale);
|
||||||
|
@ -184,12 +175,12 @@ public class FastDateParserSDFTest {
|
||||||
fdfE = e.getClass();
|
fdfE = e.getClass();
|
||||||
}
|
}
|
||||||
if (valid) {
|
if (valid) {
|
||||||
assertEquals(locale.toString()+" "+formattedDate +"\n",expectedTime, actualTime);
|
assertEquals(expectedTime, actualTime, locale.toString()+" "+formattedDate +"\n");
|
||||||
} else {
|
} else {
|
||||||
assertEquals(locale.toString()+" "+formattedDate + " expected same Exception ", sdfE, fdfE);
|
assertEquals(sdfE, fdfE, locale.toString()+" "+formattedDate + " expected same Exception ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void checkParsePosition(final String formattedDate) {
|
private void checkParsePosition(final String formattedDate, String format, Locale locale, boolean valid) {
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
|
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
|
||||||
sdf.setTimeZone(timeZone);
|
sdf.setTimeZone(timeZone);
|
||||||
final DateParser fdf = new FastDateParser(format, timeZone, locale);
|
final DateParser fdf = new FastDateParser(format, timeZone, locale);
|
||||||
|
@ -198,7 +189,7 @@ public class FastDateParserSDFTest {
|
||||||
final Date expectedTime = sdf.parse(formattedDate, sdfP);
|
final Date expectedTime = sdf.parse(formattedDate, sdfP);
|
||||||
final int sdferrorIndex = sdfP.getErrorIndex();
|
final int sdferrorIndex = sdfP.getErrorIndex();
|
||||||
if (valid) {
|
if (valid) {
|
||||||
assertEquals("Expected SDF error index -1 ", -1, sdferrorIndex);
|
assertEquals(-1, sdferrorIndex, "Expected SDF error index -1 ");
|
||||||
final int endIndex = sdfP.getIndex();
|
final int endIndex = sdfP.getIndex();
|
||||||
final int length = formattedDate.length();
|
final int length = formattedDate.length();
|
||||||
if (endIndex != length) {
|
if (endIndex != length) {
|
||||||
|
@ -216,15 +207,15 @@ public class FastDateParserSDFTest {
|
||||||
final Date actualTime = fdf.parse(formattedDate, fdfP);
|
final Date actualTime = fdf.parse(formattedDate, fdfP);
|
||||||
final int fdferrorIndex = fdfP.getErrorIndex();
|
final int fdferrorIndex = fdfP.getErrorIndex();
|
||||||
if (valid) {
|
if (valid) {
|
||||||
assertEquals("Expected FDF error index -1 ", -1, fdferrorIndex);
|
assertEquals(-1, fdferrorIndex, "Expected FDF error index -1 ");
|
||||||
final int endIndex = fdfP.getIndex();
|
final int endIndex = fdfP.getIndex();
|
||||||
final int length = formattedDate.length();
|
final int length = formattedDate.length();
|
||||||
assertEquals("Expected FDF to parse full string " + fdfP, length, endIndex);
|
assertEquals(length, endIndex, "Expected FDF to parse full string " + fdfP);
|
||||||
assertEquals(locale.toString()+" "+formattedDate +"\n", expectedTime, actualTime);
|
assertEquals(expectedTime, actualTime, locale.toString()+" "+formattedDate +"\n");
|
||||||
} else {
|
} else {
|
||||||
assertNotEquals("Test data error: expected FDF parse to fail, but got " + actualTime, -1, fdferrorIndex);
|
assertNotEquals(-1, fdferrorIndex, "Test data error: expected FDF parse to fail, but got " + actualTime);
|
||||||
assertTrue("FDF error index ("+ fdferrorIndex + ") should approximate SDF index (" + sdferrorIndex + ")",
|
assertTrue(sdferrorIndex - fdferrorIndex <= 4,
|
||||||
sdferrorIndex - fdferrorIndex <= 4);
|
"FDF error index ("+ fdferrorIndex + ") should approximate SDF index (" + sdferrorIndex + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -34,7 +35,7 @@ import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import org.apache.commons.lang3.LocaleUtils;
|
import org.apache.commons.lang3.LocaleUtils;
|
||||||
import org.apache.commons.lang3.SerializationUtils;
|
import org.apache.commons.lang3.SerializationUtils;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.time.FastDateParser}.
|
* Unit tests {@link org.apache.commons.lang3.time.FastDateParser}.
|
||||||
|
@ -224,7 +225,7 @@ public class FastDateParserTest {
|
||||||
final String fmt = sdf.format(in);
|
final String fmt = sdf.format(in);
|
||||||
try {
|
try {
|
||||||
final Date out = fdp.parse(fmt);
|
final Date out = fdp.parse(fmt);
|
||||||
assertEquals(locale.toString()+" "+in+" "+ format+ " "+tz.getID(), in, out);
|
assertEquals(in, out, locale.toString()+" "+in+" "+ format+ " "+tz.getID());
|
||||||
} catch (final ParseException pe) {
|
} catch (final ParseException pe) {
|
||||||
if (year >= 1868 || !locale.getCountry().equals("JP")) {// LANG-978
|
if (year >= 1868 || !locale.getCountry().equals("JP")) {// LANG-978
|
||||||
throw pe;
|
throw pe;
|
||||||
|
@ -271,7 +272,7 @@ public class FastDateParserTest {
|
||||||
final Date expected= cal.getTime();
|
final Date expected= cal.getTime();
|
||||||
|
|
||||||
final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale));
|
final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale));
|
||||||
assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual);
|
assertEquals(expected, actual, "tz:"+tz.getID()+" locale:"+locale.getDisplayName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -385,7 +386,7 @@ public class FastDateParserTest {
|
||||||
private void checkParse(final Locale locale, final SimpleDateFormat sdf, final DateParser fdf, final String formattedDate) throws ParseException {
|
private void checkParse(final Locale locale, final SimpleDateFormat sdf, final DateParser fdf, final String formattedDate) throws ParseException {
|
||||||
final Date expectedTime = sdf.parse(formattedDate);
|
final Date expectedTime = sdf.parse(formattedDate);
|
||||||
final Date actualTime = fdf.parse(formattedDate);
|
final Date actualTime = fdf.parse(formattedDate);
|
||||||
assertEquals(locale.toString()+" "+formattedDate +"\n",expectedTime, actualTime);
|
assertEquals(expectedTime, actualTime, locale.toString()+" "+formattedDate +"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -473,8 +474,8 @@ public class FastDateParserTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// SDF and FDF should produce equivalent results
|
// SDF and FDF should produce equivalent results
|
||||||
assertTrue("Should both or neither throw Exceptions", (f==null)==(s==null));
|
assertTrue((f==null)==(s==null), "Should both or neither throw Exceptions");
|
||||||
assertEquals("Parsed dates should be equal", dsdf, dfdp);
|
assertEquals(dsdf, dfdp, "Parsed dates should be equal");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -604,9 +605,9 @@ public class FastDateParserTest {
|
||||||
assertEquals(expected.getTime(), fdp.parse("14May2014"));
|
assertEquals(expected.getTime(), fdp.parse("14May2014"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void test1806Argument() {
|
public void test1806Argument() {
|
||||||
getInstance("XXXX");
|
assertThrows(IllegalArgumentException.class, () -> getInstance("XXXX"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Calendar initializeCalendar(final TimeZone tz) {
|
private static Calendar initializeCalendar(final TimeZone tz) {
|
||||||
|
@ -652,13 +653,13 @@ public class FastDateParserTest {
|
||||||
final String message = trial.zone.getDisplayName()+";";
|
final String message = trial.zone.getDisplayName()+";";
|
||||||
|
|
||||||
DateParser parser = getInstance(formatStub+"X", trial.zone);
|
DateParser parser = getInstance(formatStub+"X", trial.zone);
|
||||||
assertEquals(message+trial.one, cal.getTime().getTime(), parser.parse(dateStub+trial.one).getTime()-trial.offset);
|
assertEquals(cal.getTime().getTime(), parser.parse(dateStub+trial.one).getTime()-trial.offset, message+trial.one);
|
||||||
|
|
||||||
parser = getInstance(formatStub+"XX", trial.zone);
|
parser = getInstance(formatStub+"XX", trial.zone);
|
||||||
assertEquals(message+trial.two, cal.getTime(), parser.parse(dateStub+trial.two));
|
assertEquals(cal.getTime(), parser.parse(dateStub+trial.two), message+trial.two);
|
||||||
|
|
||||||
parser = getInstance(formatStub+"XXX", trial.zone);
|
parser = getInstance(formatStub+"XXX", trial.zone);
|
||||||
assertEquals(message+trial.three, cal.getTime(), parser.parse(dateStub+trial.three));
|
assertEquals(cal.getTime(), parser.parse(dateStub+trial.three), message+trial.three);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -26,7 +26,7 @@ import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class FastDateParser_MoreOrLessTest {
|
public class FastDateParser_MoreOrLessTest {
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.text.FieldPosition;
|
import java.text.FieldPosition;
|
||||||
|
@ -31,10 +32,9 @@ import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.apache.commons.lang3.SerializationUtils;
|
import org.apache.commons.lang3.SerializationUtils;
|
||||||
import org.apache.commons.lang3.test.SystemDefaults;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
import org.junitpioneer.jupiter.DefaultLocale;
|
||||||
import org.junit.Rule;
|
import org.junitpioneer.jupiter.DefaultTimeZone;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.time.FastDatePrinter}.
|
* Unit tests {@link org.apache.commons.lang3.time.FastDatePrinter}.
|
||||||
|
@ -76,10 +76,8 @@ public class FastDatePrinterTest {
|
||||||
return new FastDatePrinter(format, timeZone, locale);
|
return new FastDatePrinter(format, timeZone, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Rule
|
@DefaultLocale(language = "en", country = "US")
|
||||||
public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
|
@DefaultTimeZone("America/New_York")
|
||||||
|
|
||||||
@SystemDefaults(timezone="America/New_York", locale="en_US")
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormat() {
|
public void testFormat() {
|
||||||
final GregorianCalendar cal1 = new GregorianCalendar(2003, 0, 10, 15, 33, 20);
|
final GregorianCalendar cal1 = new GregorianCalendar(2003, 0, 10, 15, 33, 20);
|
||||||
|
@ -210,8 +208,8 @@ public class FastDatePrinterTest {
|
||||||
cal.set(2009, Calendar.OCTOBER, 16, 8, 42, 16);
|
cal.set(2009, Calendar.OCTOBER, 16, 8, 42, 16);
|
||||||
|
|
||||||
final DatePrinter format = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("GMT"));
|
final DatePrinter format = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("GMT"));
|
||||||
assertEquals("dateTime", "2009-10-16T16:42:16.000Z", format.format(cal.getTime()));
|
assertEquals("2009-10-16T16:42:16.000Z", format.format(cal.getTime()), "dateTime");
|
||||||
assertEquals("dateTime", "2009-10-16T16:42:16.000Z", format.format(cal));
|
assertEquals("2009-10-16T16:42:16.000Z", format.format(cal), "dateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -262,7 +260,7 @@ public class FastDatePrinterTest {
|
||||||
assertEquals(NEW_YORK, printer.getTimeZone());
|
assertEquals(NEW_YORK, printer.getTimeZone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(timezone="UTC")
|
@DefaultTimeZone("UTC")
|
||||||
@Test
|
@Test
|
||||||
public void testTimeZoneAsZ() throws Exception {
|
public void testTimeZoneAsZ() throws Exception {
|
||||||
final Calendar c = Calendar.getInstance(FastTimeZone.getGmtTimeZone());
|
final Calendar c = Calendar.getInstance(FastTimeZone.getGmtTimeZone());
|
||||||
|
@ -288,9 +286,9 @@ public class FastDatePrinterTest {
|
||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void test1806Argument() {
|
public void test1806Argument() {
|
||||||
getInstance("XXXX");
|
assertThrows(IllegalArgumentException.class, () -> getInstance("XXXX"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Expected1806 {
|
private enum Expected1806 {
|
||||||
|
@ -354,15 +352,15 @@ public class FastDatePrinterTest {
|
||||||
// calendar fast.
|
// calendar fast.
|
||||||
{
|
{
|
||||||
final String value = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss Z", TimeZone.getTimeZone("Europe/Paris")).format(cal);
|
final String value = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss Z", TimeZone.getTimeZone("Europe/Paris")).format(cal);
|
||||||
assertEquals("calendar", "2009-10-16T08:42:16 +0200", value);
|
assertEquals("2009-10-16T08:42:16 +0200", value, "calendar");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final String value = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss Z", TimeZone.getTimeZone("Asia/Kolkata")).format(cal);
|
final String value = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss Z", TimeZone.getTimeZone("Asia/Kolkata")).format(cal);
|
||||||
assertEquals("calendar", "2009-10-16T12:12:16 +0530", value);
|
assertEquals("2009-10-16T12:12:16 +0530", value, "calendar");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final String value = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss Z", TimeZone.getTimeZone("Europe/London")).format(cal);
|
final String value = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss Z", TimeZone.getTimeZone("Europe/London")).format(cal);
|
||||||
assertEquals("calendar", "2009-10-16T07:42:16 +0100", value);
|
assertEquals("2009-10-16T07:42:16 +0100", value, "calendar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,48 +16,34 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
public class FastDatePrinterTimeZonesTest {
|
public class FastDatePrinterTimeZonesTest {
|
||||||
|
|
||||||
private static final String PATTERN = "h:mma z";
|
private static final String PATTERN = "h:mma z";
|
||||||
|
|
||||||
@Parameterized.Parameters
|
public static Stream<TimeZone> data() {
|
||||||
public static Collection<TimeZone> data() {
|
return Arrays.stream(TimeZone.getAvailableIDs()).map(TimeZone::getTimeZone);
|
||||||
final String[] zoneIds = TimeZone.getAvailableIDs();
|
|
||||||
final List<TimeZone> timeZones = new ArrayList<>();
|
|
||||||
for (final String zoneId : zoneIds) {
|
|
||||||
timeZones.add(TimeZone.getTimeZone(zoneId));
|
|
||||||
}
|
|
||||||
return timeZones;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final TimeZone timeZone;
|
@ParameterizedTest
|
||||||
|
@MethodSource("data")
|
||||||
public FastDatePrinterTimeZonesTest(final TimeZone timeZone) {
|
public void testCalendarTimezoneRespected(TimeZone timeZone) {
|
||||||
this.timeZone = timeZone;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCalendarTimezoneRespected() {
|
|
||||||
final Calendar cal = Calendar.getInstance(timeZone);
|
final Calendar cal = Calendar.getInstance(timeZone);
|
||||||
|
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);
|
final SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);
|
||||||
sdf.setTimeZone(timeZone);
|
sdf.setTimeZone(timeZone);
|
||||||
final String expectedValue = sdf.format(cal.getTime());
|
final String expectedValue = sdf.format(cal.getTime());
|
||||||
final String actualValue = FastDateFormat.getInstance(PATTERN, this.timeZone).format(cal);
|
final String actualValue = FastDateFormat.getInstance(PATTERN, timeZone).format(cal);
|
||||||
assertEquals(expectedValue, actualValue);
|
assertEquals(expectedValue, actualValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
|
|
@ -16,19 +16,20 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for GmtTimeZone
|
* Tests for GmtTimeZone
|
||||||
*/
|
*/
|
||||||
public class GmtTimeZoneTest {
|
public class GmtTimeZoneTest {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void hoursOutOfRange() {
|
public void hoursOutOfRange() {
|
||||||
new GmtTimeZone(false, 24, 0);
|
assertThrows(IllegalArgumentException.class, () -> new GmtTimeZone(false, 24, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -36,9 +37,9 @@ public class GmtTimeZoneTest {
|
||||||
assertEquals(23 * 60 * 60 * 1000, new GmtTimeZone(false, 23, 0).getRawOffset());
|
assertEquals(23 * 60 * 60 * 1000, new GmtTimeZone(false, 23, 0).getRawOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void minutesOutOfRange() {
|
public void minutesOutOfRange() {
|
||||||
new GmtTimeZone(false, 0, 60);
|
assertThrows(IllegalArgumentException.class, () -> new GmtTimeZone(false, 0, 60));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,9 +52,9 @@ public class GmtTimeZoneTest {
|
||||||
assertEquals(0, new GmtTimeZone(false, 0, 0).getOffset(234304));
|
assertEquals(0, new GmtTimeZone(false, 0, 0).getOffset(234304));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = UnsupportedOperationException.class)
|
@Test
|
||||||
public void setRawOffset() {
|
public void setRawOffset() {
|
||||||
new GmtTimeZone(false, 0, 0).setRawOffset(0);
|
assertThrows(UnsupportedOperationException.class, () -> new GmtTimeZone(false, 0, 0).setRawOffset(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,15 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestCase for StopWatch.
|
* TestCase for StopWatch.
|
||||||
|
@ -109,8 +109,7 @@ public class StopWatchTest {
|
||||||
watch.stop();
|
watch.stop();
|
||||||
final long totalTime = watch.getTime();
|
final long totalTime = watch.getTime();
|
||||||
|
|
||||||
assertEquals("Formatted split string not the correct length",
|
assertEquals(splitStr.length(), 12, "Formatted split string not the correct length");
|
||||||
splitStr.length(), 12);
|
|
||||||
assertTrue(splitTime >= 500);
|
assertTrue(splitTime >= 500);
|
||||||
assertTrue(splitTime < 700);
|
assertTrue(splitTime < 700);
|
||||||
assertTrue(totalTime >= 1500);
|
assertTrue(totalTime >= 1500);
|
||||||
|
|
|
@ -16,58 +16,45 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.time;
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
public class WeekYearTest {
|
public class WeekYearTest {
|
||||||
|
|
||||||
@Parameters(name = "{index}: {3}")
|
public static Stream<Arguments> data() {
|
||||||
public static Collection<Object[]> data() {
|
return Stream.of(
|
||||||
return Arrays
|
Arguments.of(new GregorianCalendar( 2005, Calendar.JANUARY, 1), "2004-W53-6"),
|
||||||
.asList(new Object[][] {
|
Arguments.of(new GregorianCalendar( 2005, Calendar.JANUARY, 2), "2004-W53-7"),
|
||||||
{ 2005, Calendar.JANUARY, 1, "2004-W53-6" },
|
Arguments.of(new GregorianCalendar( 2005, Calendar.DECEMBER, 31), "2005-W52-6"),
|
||||||
{ 2005, Calendar.JANUARY, 2, "2004-W53-7" },
|
Arguments.of(new GregorianCalendar( 2007, Calendar.JANUARY, 1), "2007-W01-1"),
|
||||||
{ 2005, Calendar.DECEMBER, 31, "2005-W52-6" },
|
Arguments.of(new GregorianCalendar( 2007, Calendar.DECEMBER, 30), "2007-W52-7"),
|
||||||
{ 2007, Calendar.JANUARY, 1, "2007-W01-1" },
|
Arguments.of(new GregorianCalendar( 2007, Calendar.DECEMBER, 31), "2008-W01-1"),
|
||||||
{ 2007, Calendar.DECEMBER, 30, "2007-W52-7" },
|
Arguments.of(new GregorianCalendar( 2008, Calendar.JANUARY, 1), "2008-W01-2"),
|
||||||
{ 2007, Calendar.DECEMBER, 31, "2008-W01-1" },
|
Arguments.of(new GregorianCalendar( 2008, Calendar.DECEMBER, 28), "2008-W52-7"),
|
||||||
{ 2008, Calendar.JANUARY, 1, "2008-W01-2" },
|
Arguments.of(new GregorianCalendar( 2008, Calendar.DECEMBER, 29), "2009-W01-1"),
|
||||||
{ 2008, Calendar.DECEMBER, 28, "2008-W52-7" },
|
Arguments.of(new GregorianCalendar( 2008, Calendar.DECEMBER, 30), "2009-W01-2"),
|
||||||
{ 2008, Calendar.DECEMBER, 29, "2009-W01-1" },
|
Arguments.of(new GregorianCalendar( 2008, Calendar.DECEMBER, 31), "2009-W01-3"),
|
||||||
{ 2008, Calendar.DECEMBER, 30, "2009-W01-2" },
|
Arguments.of(new GregorianCalendar( 2009, Calendar.JANUARY, 1), "2009-W01-4"),
|
||||||
{ 2008, Calendar.DECEMBER, 31, "2009-W01-3" },
|
Arguments.of(new GregorianCalendar( 2009, Calendar.DECEMBER, 31), "2009-W53-4"),
|
||||||
{ 2009, Calendar.JANUARY, 1, "2009-W01-4" },
|
Arguments.of(new GregorianCalendar( 2010, Calendar.JANUARY, 1), "2009-W53-5"),
|
||||||
{ 2009, Calendar.DECEMBER, 31, "2009-W53-4" },
|
Arguments.of(new GregorianCalendar( 2010, Calendar.JANUARY, 2), "2009-W53-6"),
|
||||||
{ 2010, Calendar.JANUARY, 1, "2009-W53-5" },
|
Arguments.of(new GregorianCalendar( 2010, Calendar.JANUARY, 3), "2009-W53-7")
|
||||||
{ 2010, Calendar.JANUARY, 2, "2009-W53-6" },
|
);
|
||||||
{ 2010, Calendar.JANUARY, 3, "2009-W53-7" }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Calendar vulgar;
|
@ParameterizedTest
|
||||||
final String isoForm;
|
@MethodSource("data")
|
||||||
|
public void testParser(Calendar vulgar, String isoForm) {
|
||||||
public WeekYearTest(final int year, final int month, final int day, final String isoForm) {
|
|
||||||
vulgar = new GregorianCalendar(year, month, day);
|
|
||||||
this.isoForm = isoForm;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParser() throws ParseException {
|
|
||||||
final DateParser parser = new FastDateParser("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault());
|
final DateParser parser = new FastDateParser("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault());
|
||||||
|
|
||||||
final Calendar cal = Calendar.getInstance();
|
final Calendar cal = Calendar.getInstance();
|
||||||
|
@ -79,8 +66,9 @@ public class WeekYearTest {
|
||||||
assertEquals(vulgar.getTime(), cal.getTime());
|
assertEquals(vulgar.getTime(), cal.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testPrinter() {
|
@MethodSource("data")
|
||||||
|
public void testPrinter(Calendar vulgar, String isoForm) {
|
||||||
final FastDatePrinter printer = new FastDatePrinter("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault());
|
final FastDatePrinter printer = new FastDatePrinter("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault());
|
||||||
|
|
||||||
vulgar.setMinimalDaysInFirstWeek(4);
|
vulgar.setMinimalDaysInFirstWeek(4);
|
||||||
|
|
Loading…
Reference in New Issue