test/java/time/tck/java/time/format/TCKLocalizedFieldParser.java

Print this page

        

*** 57,82 **** * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package tck.java.time.format; ! import java.time.format.*; ! import static org.testng.Assert.assertEquals; - import static org.testng.Assert.fail; import java.text.ParsePosition; - import java.time.format.DateTimeBuilder; - import java.time.LocalDate; import java.time.temporal.TemporalField; import java.time.temporal.WeekFields; - import test.java.time.format.AbstractTestPrinterParser; - import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** * Test TCKLocalizedFieldParser. */ @Test(groups={"tck"}) --- 57,81 ---- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package tck.java.time.format; ! import static java.time.temporal.ChronoField.MONTH_OF_YEAR; ! import static java.time.temporal.ChronoField.YEAR; import static org.testng.Assert.assertEquals; import java.text.ParsePosition; import java.time.LocalDate; + import java.time.format.DateTimeFormatter; + import java.time.format.DateTimeFormatterBuilder; + import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalField; import java.time.temporal.WeekFields; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; + import test.java.time.format.AbstractTestPrinterParser; /** * Test TCKLocalizedFieldParser. */ @Test(groups={"tck"})
*** 112,127 **** } ParsePosition ppos = new ParsePosition(pos); DateTimeFormatterBuilder b = new DateTimeFormatterBuilder().appendPattern(pattern); DateTimeFormatter dtf = b.toFormatter(locale); ! DateTimeBuilder dtb = dtf.parseToBuilder(text, ppos); if (ppos.getErrorIndex() != -1) { assertEquals(ppos.getErrorIndex(), expectedPos); } else { assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position"); ! long value = dtb.getLong(field); assertEquals(value, expectedValue, "Value incorrect for " + field); } } //----------------------------------------------------------------------- --- 111,126 ---- } ParsePosition ppos = new ParsePosition(pos); DateTimeFormatterBuilder b = new DateTimeFormatterBuilder().appendPattern(pattern); DateTimeFormatter dtf = b.toFormatter(locale); ! TemporalAccessor parsed = dtf.parseUnresolved(text, ppos); if (ppos.getErrorIndex() != -1) { assertEquals(ppos.getErrorIndex(), expectedPos); } else { assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position"); ! long value = parsed.getLong(field); assertEquals(value, expectedValue, "Value incorrect for " + field); } } //-----------------------------------------------------------------------
*** 141,164 **** "Date: 2012-07, day-of-week: 6, week-of-month: 3", 0, 47, LocalDate.of(2012, 7, 20)}, {"'Date: 'y', day-of-week: 'e', week-of-year: 'W", "Date: 2012, day-of-week: 6, week-of-year: 29", 0, 44, LocalDate.of(2012, 7, 20)}, }; } @Test(dataProvider="LocalDatePatterns",groups={"tck"}) public void test_parse_textLocalDate(String pattern, String text, int pos, int expectedPos, LocalDate expectedValue) { - WeekFields weekDef = WeekFields.of(locale); ParsePosition ppos = new ParsePosition(pos); ! DateTimeFormatterBuilder b ! = new DateTimeFormatterBuilder().appendPattern(pattern); DateTimeFormatter dtf = b.toFormatter(locale); ! DateTimeBuilder dtb = dtf.parseToBuilder(text, ppos); if (ppos.getErrorIndex() != -1) { assertEquals(ppos.getErrorIndex(), expectedPos); } else { assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position"); ! dtb.resolve(); ! LocalDate result = dtb.query(LocalDate::from); assertEquals(result, expectedValue, "LocalDate incorrect for " + pattern); } } } --- 140,166 ---- "Date: 2012-07, day-of-week: 6, week-of-month: 3", 0, 47, LocalDate.of(2012, 7, 20)}, {"'Date: 'y', day-of-week: 'e', week-of-year: 'W", "Date: 2012, day-of-week: 6, week-of-year: 29", 0, 44, LocalDate.of(2012, 7, 20)}, }; } + @Test(dataProvider="LocalDatePatterns",groups={"tck"}) public void test_parse_textLocalDate(String pattern, String text, int pos, int expectedPos, LocalDate expectedValue) { ParsePosition ppos = new ParsePosition(pos); ! DateTimeFormatterBuilder b = new DateTimeFormatterBuilder().appendPattern(pattern); DateTimeFormatter dtf = b.toFormatter(locale); ! TemporalAccessor parsed = dtf.parseUnresolved(text, ppos); if (ppos.getErrorIndex() != -1) { assertEquals(ppos.getErrorIndex(), expectedPos); } else { assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position"); ! assertEquals(parsed.isSupported(YEAR), true); ! assertEquals(parsed.isSupported(WeekFields.of(locale).dayOfWeek()), true); ! assertEquals(parsed.isSupported(WeekFields.of(locale).weekOfMonth()) || ! parsed.isSupported(WeekFields.of(locale).weekOfYear()), true); ! // ensure combination resolves into a date ! LocalDate result = LocalDate.parse(text, dtf); assertEquals(result, expectedValue, "LocalDate incorrect for " + pattern); } } }