test/java/time/tck/java/time/format/TCKDateTimeFormatters.java
Print this page
*** 72,112 ****
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.text.ParsePosition;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Locale;
- import java.util.Map;
-
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
! import java.time.format.DateTimeBuilder;
import java.time.format.DateTimeFormatter;
- import java.time.format.DateTimeFormatters;
import java.time.format.DateTimeParseException;
! import java.time.format.DateTimePrintException;
! import java.time.temporal.ISOFields;
import java.time.temporal.Queries;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
! import java.time.temporal.Year;
! import java.time.temporal.YearMonth;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
! * Test DateTimeFormatters.
*/
@Test
public class TCKDateTimeFormatters {
@BeforeMethod
--- 72,108 ----
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.text.ParsePosition;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalDateTime;
+ import java.time.Year;
+ import java.time.YearMonth;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
! import java.time.chrono.Chronology;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
! import java.time.temporal.IsoFields;
import java.time.temporal.Queries;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
! import java.util.HashMap;
! import java.util.Iterator;
! import java.util.Locale;
! import java.util.Map;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
! * Test DateTimeFormatter.
*/
@Test
public class TCKDateTimeFormatters {
@BeforeMethod
*** 114,169 ****
}
//-----------------------------------------------------------------------
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_print_nullCalendrical() {
! DateTimeFormatters.isoDate().print((TemporalAccessor) null);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_pattern_String() {
! DateTimeFormatter test = DateTimeFormatters.pattern("d MMM yyyy");
assertEquals(test.toString(), "Value(DayOfMonth)' 'Text(MonthOfYear,SHORT)' 'Value(Year,4,19,EXCEEDS_PAD)");
assertEquals(test.getLocale(), Locale.getDefault());
}
@Test(expectedExceptions=IllegalArgumentException.class, groups={"tck"})
public void test_pattern_String_invalid() {
! DateTimeFormatters.pattern("p");
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_pattern_String_null() {
! DateTimeFormatters.pattern(null);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_pattern_StringLocale() {
! DateTimeFormatter test = DateTimeFormatters.pattern("d MMM yyyy", Locale.UK);
assertEquals(test.toString(), "Value(DayOfMonth)' 'Text(MonthOfYear,SHORT)' 'Value(Year,4,19,EXCEEDS_PAD)");
assertEquals(test.getLocale(), Locale.UK);
}
@Test(expectedExceptions=IllegalArgumentException.class, groups={"tck"})
public void test_pattern_StringLocale_invalid() {
! DateTimeFormatters.pattern("p", Locale.UK);
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_pattern_StringLocale_nullPattern() {
! DateTimeFormatters.pattern(null, Locale.UK);
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_pattern_StringLocale_nullLocale() {
! DateTimeFormatters.pattern("yyyy", null);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 110,165 ----
}
//-----------------------------------------------------------------------
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_print_nullCalendrical() {
! DateTimeFormatter.ISO_DATE.format((TemporalAccessor) null);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_pattern_String() {
! DateTimeFormatter test = DateTimeFormatter.ofPattern("d MMM yyyy");
assertEquals(test.toString(), "Value(DayOfMonth)' 'Text(MonthOfYear,SHORT)' 'Value(Year,4,19,EXCEEDS_PAD)");
assertEquals(test.getLocale(), Locale.getDefault());
}
@Test(expectedExceptions=IllegalArgumentException.class, groups={"tck"})
public void test_pattern_String_invalid() {
! DateTimeFormatter.ofPattern("p");
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_pattern_String_null() {
! DateTimeFormatter.ofPattern(null);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_pattern_StringLocale() {
! DateTimeFormatter test = DateTimeFormatter.ofPattern("d MMM yyyy", Locale.UK);
assertEquals(test.toString(), "Value(DayOfMonth)' 'Text(MonthOfYear,SHORT)' 'Value(Year,4,19,EXCEEDS_PAD)");
assertEquals(test.getLocale(), Locale.UK);
}
@Test(expectedExceptions=IllegalArgumentException.class, groups={"tck"})
public void test_pattern_StringLocale_invalid() {
! DateTimeFormatter.ofPattern("p", Locale.UK);
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_pattern_StringLocale_nullPattern() {
! DateTimeFormatter.ofPattern(null, Locale.UK);
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_pattern_StringLocale_nullLocale() {
! DateTimeFormatter.ofPattern("yyyy", null);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 191,204 ****
public void test_print_isoLocalDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoLocalDate().print(test), expected);
} else {
try {
! DateTimeFormatters.isoLocalDate().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 187,200 ----
public void test_print_isoLocalDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_LOCAL_DATE.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_LOCAL_DATE.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 207,251 ****
@Test(dataProvider="sample_isoLocalDate", groups={"tck"})
public void test_parse_isoLocalDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createDate(year, month, day);
// offset/zone not expected to be parsed
! assertParseMatch(DateTimeFormatters.isoLocalDate().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
@Test(groups={"tck"})
public void test_parse_isoLocalDate_999999999() {
! DateTimeBuilder expected = createDate(999999999, 8, 6);
! assertParseMatch(DateTimeFormatters.isoLocalDate().parseToBuilder("+999999999-08-06", new ParsePosition(0)), expected);
assertEquals(LocalDate.parse("+999999999-08-06"), LocalDate.of(999999999, 8, 6));
}
@Test(groups={"tck"})
public void test_parse_isoLocalDate_1000000000() {
! DateTimeBuilder expected = createDate(1000000000, 8, 6);
! assertParseMatch(DateTimeFormatters.isoLocalDate().parseToBuilder("+1000000000-08-06", new ParsePosition(0)), expected);
}
@Test(expectedExceptions = DateTimeException.class, groups={"tck"})
public void test_parse_isoLocalDate_1000000000_failedCreate() {
LocalDate.parse("+1000000000-08-06");
}
@Test(groups={"tck"})
public void test_parse_isoLocalDate_M999999999() {
! DateTimeBuilder expected = createDate(-999999999, 8, 6);
! assertParseMatch(DateTimeFormatters.isoLocalDate().parseToBuilder("-999999999-08-06", new ParsePosition(0)), expected);
assertEquals(LocalDate.parse("-999999999-08-06"), LocalDate.of(-999999999, 8, 6));
}
@Test(groups={"tck"})
public void test_parse_isoLocalDate_M1000000000() {
! DateTimeBuilder expected = createDate(-1000000000, 8, 6);
! assertParseMatch(DateTimeFormatters.isoLocalDate().parseToBuilder("-1000000000-08-06", new ParsePosition(0)), expected);
}
@Test(expectedExceptions = DateTimeException.class, groups={"tck"})
public void test_parse_isoLocalDate_M1000000000_failedCreate() {
LocalDate.parse("-1000000000-08-06");
--- 203,247 ----
@Test(dataProvider="sample_isoLocalDate", groups={"tck"})
public void test_parse_isoLocalDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createDate(year, month, day);
// offset/zone not expected to be parsed
! assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
@Test(groups={"tck"})
public void test_parse_isoLocalDate_999999999() {
! Expected expected = createDate(999999999, 8, 6);
! assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved("+999999999-08-06", new ParsePosition(0)), expected);
assertEquals(LocalDate.parse("+999999999-08-06"), LocalDate.of(999999999, 8, 6));
}
@Test(groups={"tck"})
public void test_parse_isoLocalDate_1000000000() {
! Expected expected = createDate(1000000000, 8, 6);
! assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved("+1000000000-08-06", new ParsePosition(0)), expected);
}
@Test(expectedExceptions = DateTimeException.class, groups={"tck"})
public void test_parse_isoLocalDate_1000000000_failedCreate() {
LocalDate.parse("+1000000000-08-06");
}
@Test(groups={"tck"})
public void test_parse_isoLocalDate_M999999999() {
! Expected expected = createDate(-999999999, 8, 6);
! assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved("-999999999-08-06", new ParsePosition(0)), expected);
assertEquals(LocalDate.parse("-999999999-08-06"), LocalDate.of(-999999999, 8, 6));
}
@Test(groups={"tck"})
public void test_parse_isoLocalDate_M1000000000() {
! Expected expected = createDate(-1000000000, 8, 6);
! assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved("-1000000000-08-06", new ParsePosition(0)), expected);
}
@Test(expectedExceptions = DateTimeException.class, groups={"tck"})
public void test_parse_isoLocalDate_M1000000000_failedCreate() {
LocalDate.parse("-1000000000-08-06");
*** 278,291 ****
public void test_print_isoOffsetDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoOffsetDate().print(test), expected);
} else {
try {
! DateTimeFormatters.isoOffsetDate().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 274,287 ----
public void test_print_isoOffsetDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_OFFSET_DATE.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_OFFSET_DATE.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 294,306 ****
@Test(dataProvider="sample_isoOffsetDate", groups={"tck"})
public void test_parse_isoOffsetDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createDate(year, month, day);
buildCalendrical(expected, offsetId, null); // zone not expected to be parsed
! assertParseMatch(DateTimeFormatters.isoOffsetDate().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 290,302 ----
@Test(dataProvider="sample_isoOffsetDate", groups={"tck"})
public void test_parse_isoOffsetDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createDate(year, month, day);
buildCalendrical(expected, offsetId, null); // zone not expected to be parsed
! assertParseMatch(DateTimeFormatter.ISO_OFFSET_DATE.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 329,342 ****
public void test_print_isoDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoDate().print(test), expected);
} else {
try {
! DateTimeFormatters.isoDate().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 325,338 ----
public void test_print_isoDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_DATE.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_DATE.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 345,359 ****
@Test(dataProvider="sample_isoDate", groups={"tck"})
public void test_parse_isoDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createDate(year, month, day);
if (offsetId != null) {
! expected.addFieldValue(OFFSET_SECONDS, ZoneOffset.of(offsetId).getTotalSeconds());
}
! assertParseMatch(DateTimeFormatters.isoDate().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 341,355 ----
@Test(dataProvider="sample_isoDate", groups={"tck"})
public void test_parse_isoDate(
Integer year, Integer month, Integer day, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createDate(year, month, day);
if (offsetId != null) {
! expected.add(ZoneOffset.of(offsetId));
}
! assertParseMatch(DateTimeFormatter.ISO_DATE.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 394,407 ****
public void test_print_isoLocalTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoLocalTime().print(test), expected);
} else {
try {
! DateTimeFormatters.isoLocalTime().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 390,403 ----
public void test_print_isoLocalTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_LOCAL_TIME.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_LOCAL_TIME.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 410,422 ****
@Test(dataProvider="sample_isoLocalTime", groups={"tck"})
public void test_parse_isoLocalTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createTime(hour, min, sec, nano);
// offset/zone not expected to be parsed
! assertParseMatch(DateTimeFormatters.isoLocalTime().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 406,418 ----
@Test(dataProvider="sample_isoLocalTime", groups={"tck"})
public void test_parse_isoLocalTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createTime(hour, min, sec, nano);
// offset/zone not expected to be parsed
! assertParseMatch(DateTimeFormatter.ISO_LOCAL_TIME.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 457,470 ****
public void test_print_isoOffsetTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoOffsetTime().print(test), expected);
} else {
try {
! DateTimeFormatters.isoOffsetTime().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 453,466 ----
public void test_print_isoOffsetTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_OFFSET_TIME.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_OFFSET_TIME.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 473,485 ****
@Test(dataProvider="sample_isoOffsetTime", groups={"tck"})
public void test_parse_isoOffsetTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createTime(hour, min, sec, nano);
buildCalendrical(expected, offsetId, null); // zoneId is not expected from parse
! assertParseMatch(DateTimeFormatters.isoOffsetTime().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 469,481 ----
@Test(dataProvider="sample_isoOffsetTime", groups={"tck"})
public void test_parse_isoOffsetTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createTime(hour, min, sec, nano);
buildCalendrical(expected, offsetId, null); // zoneId is not expected from parse
! assertParseMatch(DateTimeFormatter.ISO_OFFSET_TIME.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 520,533 ****
public void test_print_isoTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoTime().print(test), expected);
} else {
try {
! DateTimeFormatters.isoTime().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 516,529 ----
public void test_print_isoTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_TIME.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_TIME.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 536,550 ****
@Test(dataProvider="sample_isoTime", groups={"tck"})
public void test_parse_isoTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createTime(hour, min, sec, nano);
if (offsetId != null) {
! expected.addFieldValue(OFFSET_SECONDS, ZoneOffset.of(offsetId).getTotalSeconds());
}
! assertParseMatch(DateTimeFormatters.isoTime().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 532,546 ----
@Test(dataProvider="sample_isoTime", groups={"tck"})
public void test_parse_isoTime(
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createTime(hour, min, sec, nano);
if (offsetId != null) {
! expected.add(ZoneOffset.of(offsetId));
}
! assertParseMatch(DateTimeFormatter.ISO_TIME.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 594,607 ****
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoLocalDateTime().print(test), expected);
} else {
try {
! DateTimeFormatters.isoLocalDateTime().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 590,603 ----
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 611,622 ****
public void test_parse_isoLocalDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createDateTime(year, month, day, hour, min, sec, nano);
! assertParseMatch(DateTimeFormatters.isoLocalDateTime().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 607,618 ----
public void test_parse_isoLocalDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createDateTime(year, month, day, hour, min, sec, nano);
! assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 666,679 ****
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoOffsetDateTime().print(test), expected);
} else {
try {
! DateTimeFormatters.isoOffsetDateTime().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 662,675 ----
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 683,695 ****
public void test_parse_isoOffsetDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createDateTime(year, month, day, hour, min, sec, nano);
buildCalendrical(expected, offsetId, null); // zone not expected to be parsed
! assertParseMatch(DateTimeFormatters.isoOffsetDateTime().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 679,691 ----
public void test_parse_isoOffsetDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createDateTime(year, month, day, hour, min, sec, nano);
buildCalendrical(expected, offsetId, null); // zone not expected to be parsed
! assertParseMatch(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 748,761 ****
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoZonedDateTime().print(test), expected);
} else {
try {
! DateTimeFormatters.isoZonedDateTime().print(test);
fail(test.toString());
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 744,757 ----
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_ZONED_DATE_TIME.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_ZONED_DATE_TIME.format(test);
fail(test.toString());
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 765,781 ****
public void test_parse_isoZonedDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createDateTime(year, month, day, hour, min, sec, nano);
if (offsetId.equals(zoneId)) {
buildCalendrical(expected, offsetId, null);
} else {
buildCalendrical(expected, offsetId, zoneId);
}
! assertParseMatch(DateTimeFormatters.isoZonedDateTime().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 761,777 ----
public void test_parse_isoZonedDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createDateTime(year, month, day, hour, min, sec, nano);
if (offsetId.equals(zoneId)) {
buildCalendrical(expected, offsetId, null);
} else {
buildCalendrical(expected, offsetId, zoneId);
}
! assertParseMatch(DateTimeFormatter.ISO_ZONED_DATE_TIME.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 825,838 ****
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatters.isoDateTime().print(test), expected);
} else {
try {
! DateTimeFormatters.isoDateTime().print(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
--- 821,834 ----
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String expected, Class<?> expectedEx) {
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
if (expectedEx == null) {
! assertEquals(DateTimeFormatter.ISO_DATE_TIME.format(test), expected);
} else {
try {
! DateTimeFormatter.ISO_DATE_TIME.format(test);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
*** 842,965 ****
public void test_parse_isoDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! DateTimeBuilder expected = createDateTime(year, month, day, hour, min, sec, nano);
if (offsetId != null) {
! expected.addFieldValue(OFFSET_SECONDS, ZoneOffset.of(offsetId).getTotalSeconds());
if (zoneId != null) {
! expected.addCalendrical(ZoneId.of(zoneId));
}
}
! assertParseMatch(DateTimeFormatters.isoDateTime().parseToBuilder(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_print_isoOrdinalDate() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), null, null);
! assertEquals(DateTimeFormatters.isoOrdinalDate().print(test), "2008-155");
}
@Test(groups={"tck"})
public void test_print_isoOrdinalDate_offset() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "Z", null);
! assertEquals(DateTimeFormatters.isoOrdinalDate().print(test), "2008-155Z");
}
@Test(groups={"tck"})
public void test_print_isoOrdinalDate_zoned() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "+02:00", "Europe/Paris");
! assertEquals(DateTimeFormatters.isoOrdinalDate().print(test), "2008-155+02:00");
}
@Test(groups={"tck"})
public void test_print_isoOrdinalDate_zoned_largeYear() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
! assertEquals(DateTimeFormatters.isoOrdinalDate().print(test), "+123456-155Z");
}
! @Test(groups={"tck"})
public void test_print_isoOrdinalDate_fields() {
! TemporalAccessor test = new DateTimeBuilder(YEAR, 2008).addFieldValue(DAY_OF_YEAR, 231);
! assertEquals(DateTimeFormatters.isoOrdinalDate().print(test), "2008-231");
}
! @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_print_isoOrdinalDate_missingField() {
TemporalAccessor test = Year.of(2008);
! DateTimeFormatters.isoOrdinalDate().print(test);
}
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_parse_isoOrdinalDate() {
! DateTimeBuilder expected = new DateTimeBuilder(YEAR, 2008).addFieldValue(DAY_OF_YEAR, 123);
! assertParseMatch(DateTimeFormatters.isoOrdinalDate().parseToBuilder("2008-123", new ParsePosition(0)), expected);
}
@Test(groups={"tck"})
public void test_parse_isoOrdinalDate_largeYear() {
! DateTimeBuilder expected = new DateTimeBuilder(YEAR, 123456).addFieldValue(DAY_OF_YEAR, 123);
! assertParseMatch(DateTimeFormatters.isoOrdinalDate().parseToBuilder("+123456-123", new ParsePosition(0)), expected);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_print_basicIsoDate() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), null, null);
! assertEquals(DateTimeFormatters.basicIsoDate().print(test), "20080603");
}
@Test(groups={"tck"})
public void test_print_basicIsoDate_offset() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "Z", null);
! assertEquals(DateTimeFormatters.basicIsoDate().print(test), "20080603Z");
}
@Test(groups={"tck"})
public void test_print_basicIsoDate_zoned() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "+02:00", "Europe/Paris");
! assertEquals(DateTimeFormatters.basicIsoDate().print(test), "20080603+0200");
}
! @Test(expectedExceptions=DateTimePrintException.class, groups={"tck"})
public void test_print_basicIsoDate_largeYear() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
! DateTimeFormatters.basicIsoDate().print(test);
}
@Test(groups={"tck"})
public void test_print_basicIsoDate_fields() {
TemporalAccessor test = buildAccessor(LocalDate.of(2008, 6, 3), null, null);
! assertEquals(DateTimeFormatters.basicIsoDate().print(test), "20080603");
}
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_print_basicIsoDate_missingField() {
TemporalAccessor test = YearMonth.of(2008, 6);
! DateTimeFormatters.basicIsoDate().print(test);
}
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_parse_basicIsoDate() {
LocalDate expected = LocalDate.of(2008, 6, 3);
! assertEquals(DateTimeFormatters.basicIsoDate().parse("20080603", LocalDate::from), expected);
}
@Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
public void test_parse_basicIsoDate_largeYear() {
try {
LocalDate expected = LocalDate.of(123456, 6, 3);
! assertEquals(DateTimeFormatters.basicIsoDate().parse("+1234560603", LocalDate::from), expected);
} catch (DateTimeParseException ex) {
assertEquals(ex.getErrorIndex(), 0);
assertEquals(ex.getParsedString(), "+1234560603");
throw ex;
}
--- 838,977 ----
public void test_parse_isoDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
String input, Class<?> invalid) {
if (input != null) {
! Expected expected = createDateTime(year, month, day, hour, min, sec, nano);
if (offsetId != null) {
! expected.add(ZoneOffset.of(offsetId));
if (zoneId != null) {
! expected.zone = ZoneId.of(zoneId);
}
}
! assertParseMatch(DateTimeFormatter.ISO_DATE_TIME.parseUnresolved(input, new ParsePosition(0)), expected);
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_print_isoOrdinalDate() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), null, null);
! assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-155");
}
@Test(groups={"tck"})
public void test_print_isoOrdinalDate_offset() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "Z", null);
! assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-155Z");
}
@Test(groups={"tck"})
public void test_print_isoOrdinalDate_zoned() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "+02:00", "Europe/Paris");
! assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-155+02:00");
}
@Test(groups={"tck"})
public void test_print_isoOrdinalDate_zoned_largeYear() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
! assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "+123456-155Z");
}
! @Test
public void test_print_isoOrdinalDate_fields() {
! // mock for testing that does not fully comply with TemporalAccessor contract
! TemporalAccessor test = new TemporalAccessor() {
! @Override
! public boolean isSupported(TemporalField field) {
! return field == YEAR || field == DAY_OF_YEAR;
! }
! @Override
! public long getLong(TemporalField field) {
! if (field == YEAR) {
! return 2008;
! }
! if (field == DAY_OF_YEAR) {
! return 231;
! }
! throw new DateTimeException("Unsupported");
! }
! };
! assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-231");
}
! @Test(expectedExceptions=DateTimeException.class)
public void test_print_isoOrdinalDate_missingField() {
TemporalAccessor test = Year.of(2008);
! DateTimeFormatter.ISO_ORDINAL_DATE.format(test);
}
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_parse_isoOrdinalDate() {
! Expected expected = new Expected(YEAR, 2008, DAY_OF_YEAR, 123);
! assertParseMatch(DateTimeFormatter.ISO_ORDINAL_DATE.parseUnresolved("2008-123", new ParsePosition(0)), expected);
}
@Test(groups={"tck"})
public void test_parse_isoOrdinalDate_largeYear() {
! Expected expected = new Expected(YEAR, 123456, DAY_OF_YEAR, 123);
! assertParseMatch(DateTimeFormatter.ISO_ORDINAL_DATE.parseUnresolved("+123456-123", new ParsePosition(0)), expected);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_print_basicIsoDate() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), null, null);
! assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603");
}
@Test(groups={"tck"})
public void test_print_basicIsoDate_offset() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "Z", null);
! assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603Z");
}
@Test(groups={"tck"})
public void test_print_basicIsoDate_zoned() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "+02:00", "Europe/Paris");
! assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603+0200");
}
! @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_print_basicIsoDate_largeYear() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
! DateTimeFormatter.BASIC_ISO_DATE.format(test);
}
@Test(groups={"tck"})
public void test_print_basicIsoDate_fields() {
TemporalAccessor test = buildAccessor(LocalDate.of(2008, 6, 3), null, null);
! assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603");
}
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_print_basicIsoDate_missingField() {
TemporalAccessor test = YearMonth.of(2008, 6);
! DateTimeFormatter.BASIC_ISO_DATE.format(test);
}
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_parse_basicIsoDate() {
LocalDate expected = LocalDate.of(2008, 6, 3);
! assertEquals(DateTimeFormatter.BASIC_ISO_DATE.parse("20080603", LocalDate::from), expected);
}
@Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
public void test_parse_basicIsoDate_largeYear() {
try {
LocalDate expected = LocalDate.of(123456, 6, 3);
! assertEquals(DateTimeFormatter.BASIC_ISO_DATE.parse("+1234560603", LocalDate::from), expected);
} catch (DateTimeParseException ex) {
assertEquals(ex.getErrorIndex(), 0);
assertEquals(ex.getParsedString(), "+1234560603");
throw ex;
}
*** 1000,1043 ****
};
}
@Test(dataProvider="weekDate", groups={"tck"})
public void test_print_isoWeekDate(TemporalAccessor test, String expected) {
! assertEquals(DateTimeFormatters.isoWeekDate().print(test), expected);
}
@Test(groups={"tck"})
public void test_print_isoWeekDate_zoned_largeYear() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
! assertEquals(DateTimeFormatters.isoWeekDate().print(test), "+123456-W23-2Z");
}
@Test(groups={"tck"})
public void test_print_isoWeekDate_fields() {
TemporalAccessor test = buildAccessor(LocalDate.of(2004, 1, 27), null, null);
! assertEquals(DateTimeFormatters.isoWeekDate().print(test), "2004-W05-2");
}
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_print_isoWeekDate_missingField() {
TemporalAccessor test = YearMonth.of(2008, 6);
! DateTimeFormatters.isoWeekDate().print(test);
}
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_parse_weekDate() {
LocalDate expected = LocalDate.of(2004, 1, 28);
! assertEquals(DateTimeFormatters.isoWeekDate().parse("2004-W05-3", LocalDate::from), expected);
}
@Test(groups={"tck"})
public void test_parse_weekDate_largeYear() {
! DateTimeBuilder builder = DateTimeFormatters.isoWeekDate().parseToBuilder("+123456-W04-5", new ParsePosition(0));
! assertEquals(builder.getFieldValue(ISOFields.WEEK_BASED_YEAR), 123456);
! assertEquals(builder.getFieldValue(ISOFields.WEEK_OF_WEEK_BASED_YEAR), 4);
! assertEquals(builder.getFieldValue(DAY_OF_WEEK), 5);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
--- 1012,1055 ----
};
}
@Test(dataProvider="weekDate", groups={"tck"})
public void test_print_isoWeekDate(TemporalAccessor test, String expected) {
! assertEquals(DateTimeFormatter.ISO_WEEK_DATE.format(test), expected);
}
@Test(groups={"tck"})
public void test_print_isoWeekDate_zoned_largeYear() {
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
! assertEquals(DateTimeFormatter.ISO_WEEK_DATE.format(test), "+123456-W23-2Z");
}
@Test(groups={"tck"})
public void test_print_isoWeekDate_fields() {
TemporalAccessor test = buildAccessor(LocalDate.of(2004, 1, 27), null, null);
! assertEquals(DateTimeFormatter.ISO_WEEK_DATE.format(test), "2004-W05-2");
}
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_print_isoWeekDate_missingField() {
TemporalAccessor test = YearMonth.of(2008, 6);
! DateTimeFormatter.ISO_WEEK_DATE.format(test);
}
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_parse_weekDate() {
LocalDate expected = LocalDate.of(2004, 1, 28);
! assertEquals(DateTimeFormatter.ISO_WEEK_DATE.parse("2004-W05-3", LocalDate::from), expected);
}
@Test(groups={"tck"})
public void test_parse_weekDate_largeYear() {
! TemporalAccessor parsed = DateTimeFormatter.ISO_WEEK_DATE.parseUnresolved("+123456-W04-5", new ParsePosition(0));
! assertEquals(parsed.getLong(IsoFields.WEEK_BASED_YEAR), 123456L);
! assertEquals(parsed.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR), 4L);
! assertEquals(parsed.getLong(DAY_OF_WEEK), 5L);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
*** 1052,1134 ****
}
@Test(groups={"tck"}, dataProvider="rfc")
public void test_print_rfc1123(LocalDateTime base, String offsetId, String expected) {
TemporalAccessor test = buildAccessor(base, offsetId, null);
! assertEquals(DateTimeFormatters.rfc1123().print(test), expected);
}
@Test(groups={"tck"}, dataProvider="rfc")
public void test_print_rfc1123_french(LocalDateTime base, String offsetId, String expected) {
TemporalAccessor test = buildAccessor(base, offsetId, null);
! assertEquals(DateTimeFormatters.rfc1123().withLocale(Locale.FRENCH).print(test), expected);
}
@Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
public void test_print_rfc1123_missingField() {
TemporalAccessor test = YearMonth.of(2008, 6);
! DateTimeFormatters.rfc1123().print(test);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
! private DateTimeBuilder createDate(Integer year, Integer month, Integer day) {
! DateTimeBuilder test = new DateTimeBuilder();
if (year != null) {
! test.addFieldValue(YEAR, year);
}
if (month != null) {
! test.addFieldValue(MONTH_OF_YEAR, month);
}
if (day != null) {
! test.addFieldValue(DAY_OF_MONTH, day);
}
return test;
}
! private DateTimeBuilder createTime(Integer hour, Integer min, Integer sec, Integer nano) {
! DateTimeBuilder test = new DateTimeBuilder();
if (hour != null) {
! test.addFieldValue(HOUR_OF_DAY, hour);
}
if (min != null) {
! test.addFieldValue(MINUTE_OF_HOUR, min);
}
if (sec != null) {
! test.addFieldValue(SECOND_OF_MINUTE, sec);
}
if (nano != null) {
! test.addFieldValue(NANO_OF_SECOND, nano);
}
return test;
}
! private DateTimeBuilder createDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano) {
! DateTimeBuilder test = new DateTimeBuilder();
if (year != null) {
! test.addFieldValue(YEAR, year);
}
if (month != null) {
! test.addFieldValue(MONTH_OF_YEAR, month);
}
if (day != null) {
! test.addFieldValue(DAY_OF_MONTH, day);
}
if (hour != null) {
! test.addFieldValue(HOUR_OF_DAY, hour);
}
if (min != null) {
! test.addFieldValue(MINUTE_OF_HOUR, min);
}
if (sec != null) {
! test.addFieldValue(SECOND_OF_MINUTE, sec);
}
if (nano != null) {
! test.addFieldValue(NANO_OF_SECOND, nano);
}
return test;
}
private TemporalAccessor buildAccessor(
--- 1064,1146 ----
}
@Test(groups={"tck"}, dataProvider="rfc")
public void test_print_rfc1123(LocalDateTime base, String offsetId, String expected) {
TemporalAccessor test = buildAccessor(base, offsetId, null);
! assertEquals(DateTimeFormatter.RFC_1123_DATE_TIME.format(test), expected);
}
@Test(groups={"tck"}, dataProvider="rfc")
public void test_print_rfc1123_french(LocalDateTime base, String offsetId, String expected) {
TemporalAccessor test = buildAccessor(base, offsetId, null);
! assertEquals(DateTimeFormatter.RFC_1123_DATE_TIME.withLocale(Locale.FRENCH).format(test), expected);
}
@Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
public void test_print_rfc1123_missingField() {
TemporalAccessor test = YearMonth.of(2008, 6);
! DateTimeFormatter.RFC_1123_DATE_TIME.format(test);
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
! private Expected createDate(Integer year, Integer month, Integer day) {
! Expected test = new Expected();
if (year != null) {
! test.fieldValues.put(YEAR, (long) year);
}
if (month != null) {
! test.fieldValues.put(MONTH_OF_YEAR, (long) month);
}
if (day != null) {
! test.fieldValues.put(DAY_OF_MONTH, (long) day);
}
return test;
}
! private Expected createTime(Integer hour, Integer min, Integer sec, Integer nano) {
! Expected test = new Expected();
if (hour != null) {
! test.fieldValues.put(HOUR_OF_DAY, (long) hour);
}
if (min != null) {
! test.fieldValues.put(MINUTE_OF_HOUR, (long) min);
}
if (sec != null) {
! test.fieldValues.put(SECOND_OF_MINUTE, (long) sec);
}
if (nano != null) {
! test.fieldValues.put(NANO_OF_SECOND, (long) nano);
}
return test;
}
! private Expected createDateTime(
Integer year, Integer month, Integer day,
Integer hour, Integer min, Integer sec, Integer nano) {
! Expected test = new Expected();
if (year != null) {
! test.fieldValues.put(YEAR, (long) year);
}
if (month != null) {
! test.fieldValues.put(MONTH_OF_YEAR, (long) month);
}
if (day != null) {
! test.fieldValues.put(DAY_OF_MONTH, (long) day);
}
if (hour != null) {
! test.fieldValues.put(HOUR_OF_DAY, (long) hour);
}
if (min != null) {
! test.fieldValues.put(MINUTE_OF_HOUR, (long) min);
}
if (sec != null) {
! test.fieldValues.put(SECOND_OF_MINUTE, (long) sec);
}
if (nano != null) {
! test.fieldValues.put(NANO_OF_SECOND, (long) nano);
}
return test;
}
private TemporalAccessor buildAccessor(
*** 1176,1202 ****
mock.setOffset(offsetId);
mock.setZone(zoneId);
return mock;
}
! private void buildCalendrical(DateTimeBuilder cal, String offsetId, String zoneId) {
if (offsetId != null) {
! cal.addFieldValue(OFFSET_SECONDS, ZoneOffset.of(offsetId).getTotalSeconds());
}
if (zoneId != null) {
! cal.addCalendrical(ZoneId.of(zoneId));
}
}
! private void assertParseMatch(DateTimeBuilder parsed, DateTimeBuilder expected) {
! Map<TemporalField, Long> parsedFVMap = parsed.getFieldValueMap();
! Map<TemporalField, Long> expectedFVMap = expected.getFieldValueMap();
! assertEquals(parsedFVMap, expectedFVMap);
!
! List<Object> parsedCMap = parsed.getCalendricalList();
! List<Object> expectedCMap = expected.getCalendricalList();
! assertEquals(parsedCMap, expectedCMap);
}
//-------------------------------------------------------------------------
Map<TemporalField, Long> fields = new HashMap<>();
ZoneId zoneId;
--- 1188,1213 ----
mock.setOffset(offsetId);
mock.setZone(zoneId);
return mock;
}
! private void buildCalendrical(Expected expected, String offsetId, String zoneId) {
if (offsetId != null) {
! expected.add(ZoneOffset.of(offsetId));
}
if (zoneId != null) {
! expected.zone = ZoneId.of(zoneId);
}
}
! private void assertParseMatch(TemporalAccessor parsed, Expected expected) {
! for (TemporalField field : expected.fieldValues.keySet()) {
! assertEquals(parsed.isSupported(field), true);
! parsed.getLong(field);
! }
! assertEquals(parsed.query(Queries.chronology()), expected.chrono);
! assertEquals(parsed.query(Queries.zoneId()), expected.zone);
}
//-------------------------------------------------------------------------
Map<TemporalField, Long> fields = new HashMap<>();
ZoneId zoneId;
*** 1209,1232 ****
fields.put(YEAR, (long) dt.getYear());
fields.put(MONTH_OF_YEAR, (long) dt.getMonthValue());
fields.put(DAY_OF_MONTH, (long) dt.getDayOfMonth());
fields.put(DAY_OF_YEAR, (long) dt.getDayOfYear());
fields.put(DAY_OF_WEEK, (long) dt.getDayOfWeek().getValue());
! fields.put(ISOFields.WEEK_BASED_YEAR, dt.getLong(ISOFields.WEEK_BASED_YEAR));
! fields.put(ISOFields.WEEK_OF_WEEK_BASED_YEAR, dt.getLong(ISOFields.WEEK_OF_WEEK_BASED_YEAR));
}
}
void setFields(LocalDateTime dt) {
if (dt != null) {
fields.put(YEAR, (long) dt.getYear());
fields.put(MONTH_OF_YEAR, (long) dt.getMonthValue());
fields.put(DAY_OF_MONTH, (long) dt.getDayOfMonth());
fields.put(DAY_OF_YEAR, (long) dt.getDayOfYear());
fields.put(DAY_OF_WEEK, (long) dt.getDayOfWeek().getValue());
! fields.put(ISOFields.WEEK_BASED_YEAR, dt.getLong(ISOFields.WEEK_BASED_YEAR));
! fields.put(ISOFields.WEEK_OF_WEEK_BASED_YEAR, dt.getLong(ISOFields.WEEK_OF_WEEK_BASED_YEAR));
fields.put(HOUR_OF_DAY, (long) dt.getHour());
fields.put(MINUTE_OF_HOUR, (long) dt.getMinute());
fields.put(SECOND_OF_MINUTE, (long) dt.getSecond());
fields.put(NANO_OF_SECOND, (long) dt.getNano());
}
--- 1220,1243 ----
fields.put(YEAR, (long) dt.getYear());
fields.put(MONTH_OF_YEAR, (long) dt.getMonthValue());
fields.put(DAY_OF_MONTH, (long) dt.getDayOfMonth());
fields.put(DAY_OF_YEAR, (long) dt.getDayOfYear());
fields.put(DAY_OF_WEEK, (long) dt.getDayOfWeek().getValue());
! fields.put(IsoFields.WEEK_BASED_YEAR, dt.getLong(IsoFields.WEEK_BASED_YEAR));
! fields.put(IsoFields.WEEK_OF_WEEK_BASED_YEAR, dt.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR));
}
}
void setFields(LocalDateTime dt) {
if (dt != null) {
fields.put(YEAR, (long) dt.getYear());
fields.put(MONTH_OF_YEAR, (long) dt.getMonthValue());
fields.put(DAY_OF_MONTH, (long) dt.getDayOfMonth());
fields.put(DAY_OF_YEAR, (long) dt.getDayOfYear());
fields.put(DAY_OF_WEEK, (long) dt.getDayOfWeek().getValue());
! fields.put(IsoFields.WEEK_BASED_YEAR, dt.getLong(IsoFields.WEEK_BASED_YEAR));
! fields.put(IsoFields.WEEK_OF_WEEK_BASED_YEAR, dt.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR));
fields.put(HOUR_OF_DAY, (long) dt.getHour());
fields.put(MINUTE_OF_HOUR, (long) dt.getMinute());
fields.put(SECOND_OF_MINUTE, (long) dt.getSecond());
fields.put(NANO_OF_SECOND, (long) dt.getNano());
}
*** 1271,1276 ****
--- 1282,1305 ----
public String toString() {
return fields + (zoneId != null ? " " + zoneId : "");
}
}
+ //-----------------------------------------------------------------------
+ static class Expected {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ ZoneId zone;
+ Chronology chrono;
+
+ Expected() {
+ }
+
+ Expected(TemporalField field1, long value1, TemporalField field2, long value2) {
+ fieldValues.put(field1, value1);
+ fieldValues.put(field2, value2);
+ }
+
+ void add(ZoneOffset offset) {
+ fieldValues.put(OFFSET_SECONDS, (long) offset.getTotalSeconds());
+ }
+ }
}