< prev index next >

test/java/time/tck/java/time/format/TCKDateTimeFormatterBuilder.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 69,78 **** --- 69,79 ---- import static java.time.temporal.ChronoField.YEAR; import static org.testng.Assert.assertEquals; import java.text.ParsePosition; import java.time.LocalDate; + import java.time.LocalDateTime; import java.time.YearMonth; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException;
*** 880,912 **** assertEquals(parsed.getLong(HOUR_OF_DAY), 12L); assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L); assertEquals(parsed.getLong(NANO_OF_SECOND), 567_000_000L); } ! @Test public void test_adjacent_lenient_fractionFollows_2digit() throws Exception { ! // succeeds because hour/min are fixed width DateTimeFormatter f = builder.parseLenient().appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 3, 3, false).toFormatter(Locale.UK); ParsePosition pp = new ParsePosition(0); TemporalAccessor parsed = f.parseUnresolved("123056", pp); - assertEquals(pp.getErrorIndex(), -1); - assertEquals(pp.getIndex(), 6); assertEquals(parsed.getLong(HOUR_OF_DAY), 12L); assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L); ! assertEquals(parsed.getLong(NANO_OF_SECOND), 560_000_000L); } ! @Test public void test_adjacent_lenient_fractionFollows_0digit() throws Exception { ! // succeeds because hour/min are fixed width DateTimeFormatter f = builder.parseLenient().appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 3, 3, false).toFormatter(Locale.UK); ParsePosition pp = new ParsePosition(0); TemporalAccessor parsed = f.parseUnresolved("1230", pp); - assertEquals(pp.getErrorIndex(), -1); - assertEquals(pp.getIndex(), 4); assertEquals(parsed.getLong(HOUR_OF_DAY), 12L); assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L); } @DataProvider(name="lenientOffsetParseData") Object[][] data_lenient_offset_parse() { return new Object[][] { --- 881,925 ---- assertEquals(parsed.getLong(HOUR_OF_DAY), 12L); assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L); assertEquals(parsed.getLong(NANO_OF_SECOND), 567_000_000L); } ! @Test(expectedExceptions=NullPointerException.class) public void test_adjacent_lenient_fractionFollows_2digit() throws Exception { ! // fails because hour,min and fraction of seconds are fixed width DateTimeFormatter f = builder.parseLenient().appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 3, 3, false).toFormatter(Locale.UK); ParsePosition pp = new ParsePosition(0); TemporalAccessor parsed = f.parseUnresolved("123056", pp); assertEquals(parsed.getLong(HOUR_OF_DAY), 12L); assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L); ! assertEquals(parsed.getLong(NANO_OF_SECOND), 560_000_000L); // fails here } ! @Test(expectedExceptions=NullPointerException.class) public void test_adjacent_lenient_fractionFollows_0digit() throws Exception { ! // fails because hour, min and fraction of seconds are fixed width DateTimeFormatter f = builder.parseLenient().appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 3, 3, false).toFormatter(Locale.UK); ParsePosition pp = new ParsePosition(0); TemporalAccessor parsed = f.parseUnresolved("1230", pp); assertEquals(parsed.getLong(HOUR_OF_DAY), 12L); assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L); + assertEquals(parsed.getLong(NANO_OF_SECOND), 0L); // fails here + } + + @DataProvider(name="adjacentFractionParseData") + Object[][] data_adjacent_fraction_parse() { + return new Object[][] { + {"20130812214600025", "yyyyMMddHHmmssSSS", LocalDateTime.of(2013, 8, 12, 21, 46, 00, 25000000)}, + {"201308122146000256", "yyyyMMddHHmmssSSSS", LocalDateTime.of(2013, 8, 12, 21, 46, 00, 25600000)}, + }; + } + + @Test(dataProvider = "adjacentFractionParseData") + public void test_adjacent_fraction(String input, String pattern, LocalDateTime expected) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern); + LocalDateTime actual = LocalDateTime.parse(input, dtf); + assertEquals(actual, expected); } @DataProvider(name="lenientOffsetParseData") Object[][] data_lenient_offset_parse() { return new Object[][] {
< prev index next >