1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * This file is available under and governed by the GNU General Public 26 * License version 2 only, as published by the Free Software Foundation. 27 * However, the following notice accompanied the original version of this 28 * file: 29 * 30 * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos 31 * 32 * All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions are met: 36 * 37 * * Redistributions of source code must retain the above copyright notice, 38 * this list of conditions and the following disclaimer. 39 * 40 * * Redistributions in binary form must reproduce the above copyright notice, 41 * this list of conditions and the following disclaimer in the documentation 42 * and/or other materials provided with the distribution. 43 * 44 * * Neither the name of JSR-310 nor the names of its contributors 45 * may be used to endorse or promote products derived from this software 46 * without specific prior written permission. 47 * 48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 49 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 50 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 51 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 55 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 56 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 57 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 58 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 */ 60 package test.java.time.format; 61 62 import static java.time.temporal.ChronoField.DAY_OF_MONTH; 63 import static java.time.temporal.ChronoField.DAY_OF_WEEK; 64 import static java.time.temporal.ChronoField.MONTH_OF_YEAR; 65 import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; 66 import static org.testng.Assert.assertEquals; 67 import static org.testng.Assert.assertTrue; 68 69 import java.text.ParsePosition; 70 import java.time.DayOfWeek; 71 import java.time.chrono.ChronoLocalDate; 72 import java.time.chrono.JapaneseChronology; 73 import java.time.chrono.HijrahDate; 74 import java.time.chrono.JapaneseDate; 75 import java.time.chrono.MinguoDate; 76 import java.time.chrono.ThaiBuddhistDate; 77 import java.time.format.DateTimeFormatter; 78 import java.time.format.DateTimeFormatterBuilder; 79 import java.time.format.TextStyle; 80 import java.time.format.SignStyle; 81 import java.time.temporal.TemporalAccessor; 82 import java.time.temporal.TemporalField; 83 import java.time.temporal.TemporalQueries; 84 import java.time.temporal.ChronoField; 85 import java.util.Locale; 86 87 import org.testng.annotations.DataProvider; 88 import org.testng.annotations.Test; 89 90 /** 91 * Test TextPrinterParser. 92 */ 93 @Test 94 public class TestTextParser extends AbstractTestPrinterParser { 95 static final Locale RUSSIAN = new Locale("ru"); 96 static final Locale FINNISH = new Locale("fi"); 97 98 //----------------------------------------------------------------------- 99 @DataProvider(name="error") 100 Object[][] data_error() { 101 return new Object[][] { 102 {DAY_OF_WEEK, TextStyle.FULL, "Monday", -1, IndexOutOfBoundsException.class}, 103 {DAY_OF_WEEK, TextStyle.FULL, "Monday", 7, IndexOutOfBoundsException.class}, 104 }; 105 } 106 107 @Test(dataProvider="error") 108 public void test_parse_error(TemporalField field, TextStyle style, String text, int pos, Class<?> expected) { 109 try { 110 getFormatter(field, style).parseUnresolved(text, new ParsePosition(pos)); 111 } catch (RuntimeException ex) { 112 assertTrue(expected.isInstance(ex)); 113 } 114 } 115 116 //----------------------------------------------------------------------- 117 public void test_parse_midStr() throws Exception { 118 ParsePosition pos = new ParsePosition(3); 119 assertEquals(getFormatter(DAY_OF_WEEK, TextStyle.FULL) 120 .parseUnresolved("XxxMondayXxx", pos) 121 .getLong(DAY_OF_WEEK), 1L); 122 assertEquals(pos.getIndex(), 9); 123 } 124 125 public void test_parse_remainderIgnored() throws Exception { 126 ParsePosition pos = new ParsePosition(0); 127 assertEquals(getFormatter(DAY_OF_WEEK, TextStyle.SHORT) 128 .parseUnresolved("Wednesday", pos) 129 .getLong(DAY_OF_WEEK), 3L); 130 assertEquals(pos.getIndex(), 3); 131 } 132 133 //----------------------------------------------------------------------- 134 public void test_parse_noMatch1() throws Exception { 135 ParsePosition pos = new ParsePosition(0); 136 TemporalAccessor parsed = 137 getFormatter(DAY_OF_WEEK, TextStyle.FULL).parseUnresolved("Munday", pos); 138 assertEquals(pos.getErrorIndex(), 0); 139 assertEquals(parsed, null); 140 } 141 142 public void test_parse_noMatch2() throws Exception { 143 ParsePosition pos = new ParsePosition(3); 144 TemporalAccessor parsed = 145 getFormatter(DAY_OF_WEEK, TextStyle.FULL).parseUnresolved("Monday", pos); 146 assertEquals(pos.getErrorIndex(), 3); 147 assertEquals(parsed, null); 148 } 149 150 public void test_parse_noMatch_atEnd() throws Exception { 151 ParsePosition pos = new ParsePosition(6); 152 TemporalAccessor parsed = 153 getFormatter(DAY_OF_WEEK, TextStyle.FULL).parseUnresolved("Monday", pos); 154 assertEquals(pos.getErrorIndex(), 6); 155 assertEquals(parsed, null); 156 } 157 158 //----------------------------------------------------------------------- 159 @DataProvider(name="parseText") 160 Object[][] provider_text() { 161 return new Object[][] { 162 {DAY_OF_WEEK, TextStyle.FULL, 1, "Monday"}, 163 {DAY_OF_WEEK, TextStyle.FULL, 2, "Tuesday"}, 164 {DAY_OF_WEEK, TextStyle.FULL, 3, "Wednesday"}, 165 {DAY_OF_WEEK, TextStyle.FULL, 4, "Thursday"}, 166 {DAY_OF_WEEK, TextStyle.FULL, 5, "Friday"}, 167 {DAY_OF_WEEK, TextStyle.FULL, 6, "Saturday"}, 168 {DAY_OF_WEEK, TextStyle.FULL, 7, "Sunday"}, 169 170 {DAY_OF_WEEK, TextStyle.SHORT, 1, "Mon"}, 171 {DAY_OF_WEEK, TextStyle.SHORT, 2, "Tue"}, 172 {DAY_OF_WEEK, TextStyle.SHORT, 3, "Wed"}, 173 {DAY_OF_WEEK, TextStyle.SHORT, 4, "Thu"}, 174 {DAY_OF_WEEK, TextStyle.SHORT, 5, "Fri"}, 175 {DAY_OF_WEEK, TextStyle.SHORT, 6, "Sat"}, 176 {DAY_OF_WEEK, TextStyle.SHORT, 7, "Sun"}, 177 178 {MONTH_OF_YEAR, TextStyle.FULL, 1, "January"}, 179 {MONTH_OF_YEAR, TextStyle.FULL, 12, "December"}, 180 181 {MONTH_OF_YEAR, TextStyle.SHORT, 1, "Jan"}, 182 {MONTH_OF_YEAR, TextStyle.SHORT, 12, "Dec"}, 183 184 {QUARTER_OF_YEAR, TextStyle.FULL, 1, "1st quarter"}, 185 {QUARTER_OF_YEAR, TextStyle.FULL, 2, "2nd quarter"}, 186 {QUARTER_OF_YEAR, TextStyle.FULL, 3, "3rd quarter"}, 187 {QUARTER_OF_YEAR, TextStyle.FULL, 4, "4th quarter"}, 188 189 {QUARTER_OF_YEAR, TextStyle.SHORT, 1, "Q1"}, 190 {QUARTER_OF_YEAR, TextStyle.SHORT, 2, "Q2"}, 191 {QUARTER_OF_YEAR, TextStyle.SHORT, 3, "Q3"}, 192 {QUARTER_OF_YEAR, TextStyle.SHORT, 4, "Q4"}, 193 194 {QUARTER_OF_YEAR, TextStyle.NARROW, 1, "1"}, 195 {QUARTER_OF_YEAR, TextStyle.NARROW, 2, "2"}, 196 {QUARTER_OF_YEAR, TextStyle.NARROW, 3, "3"}, 197 {QUARTER_OF_YEAR, TextStyle.NARROW, 4, "4"}, 198 }; 199 } 200 201 @DataProvider(name="parseNumber") 202 Object[][] provider_number() { 203 return new Object[][] { 204 {DAY_OF_MONTH, TextStyle.FULL, 1, "1"}, 205 {DAY_OF_MONTH, TextStyle.FULL, 2, "2"}, 206 {DAY_OF_MONTH, TextStyle.FULL, 30, "30"}, 207 {DAY_OF_MONTH, TextStyle.FULL, 31, "31"}, 208 209 {DAY_OF_MONTH, TextStyle.SHORT, 1, "1"}, 210 {DAY_OF_MONTH, TextStyle.SHORT, 2, "2"}, 211 {DAY_OF_MONTH, TextStyle.SHORT, 30, "30"}, 212 {DAY_OF_MONTH, TextStyle.SHORT, 31, "31"}, 213 }; 214 } 215 216 // Test data is dependent on localized resources. 217 @DataProvider(name="parseStandaloneText") 218 Object[][] providerStandaloneText() { 219 // Locale, TemporalField, TextStyle, expected value, input text 220 return new Object[][] { 221 {RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE, 1, "\u042f\u043d\u0432\u0430\u0440\u044c"}, 222 {RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE, 12, "\u0414\u0435\u043a\u0430\u0431\u0440\u044c"}, 223 {RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, 1, "\u042f\u043d\u0432."}, 224 {RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, 12, "\u0414\u0435\u043a."}, 225 {FINNISH, DAY_OF_WEEK, TextStyle.FULL_STANDALONE, 2, "tiistai"}, 226 {FINNISH, DAY_OF_WEEK, TextStyle.SHORT_STANDALONE, 2, "ti"}, 227 }; 228 } 229 230 @DataProvider(name="parseDayOfWeekText") 231 Object[][] providerDayOfWeekData() { 232 return new Object[][] { 233 // Locale, pattern, input text, expected DayOfWeek 234 {Locale.US, "e", "1", DayOfWeek.SUNDAY}, 235 {Locale.US, "ee", "01", DayOfWeek.SUNDAY}, 236 {Locale.US, "c", "1", DayOfWeek.SUNDAY}, 237 238 {Locale.UK, "e", "1", DayOfWeek.MONDAY}, 239 {Locale.UK, "ee", "01", DayOfWeek.MONDAY}, 240 {Locale.UK, "c", "1", DayOfWeek.MONDAY}, 241 }; 242 } 243 244 // Test data is dependent on localized resources. 245 @DataProvider(name="parseLenientText") 246 Object[][] providerLenientText() { 247 // Locale, TemporalField, expected value, input text 248 return new Object[][] { 249 {RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432\u0430\u0440\u044f"}, // full format 250 {RUSSIAN, MONTH_OF_YEAR, 1, "\u042f\u043d\u0432\u0430\u0440\u044c"}, // full standalone 251 {RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432"}, // short format 252 {RUSSIAN, MONTH_OF_YEAR, 1, "\u042f\u043d\u0432."}, // short standalone 253 }; 254 } 255 256 257 258 @Test(dataProvider="parseText") 259 public void test_parseText(TemporalField field, TextStyle style, int value, String input) throws Exception { 260 ParsePosition pos = new ParsePosition(0); 261 assertEquals(getFormatter(field, style).parseUnresolved(input, pos).getLong(field), (long) value); 262 assertEquals(pos.getIndex(), input.length()); 263 } 264 265 @Test(dataProvider="parseNumber") 266 public void test_parseNumber(TemporalField field, TextStyle style, int value, String input) throws Exception { 267 ParsePosition pos = new ParsePosition(0); 268 assertEquals(getFormatter(field, style).parseUnresolved(input, pos).getLong(field), (long) value); 269 assertEquals(pos.getIndex(), input.length()); 270 } 271 272 @Test(dataProvider="parseStandaloneText") 273 public void test_parseStandaloneText(Locale locale, TemporalField field, TextStyle style, int expectedValue, String input) { 274 DateTimeFormatter formatter = getFormatter(field, style).withLocale(locale); 275 ParsePosition pos = new ParsePosition(0); 276 assertEquals(formatter.parseUnresolved(input, pos).getLong(field), (long) expectedValue); 277 assertEquals(pos.getIndex(), input.length()); 278 } 279 280 @Test(dataProvider="parseDayOfWeekText") 281 public void test_parseDayOfWeekText(Locale locale, String pattern, String input, DayOfWeek expected) { 282 DateTimeFormatter formatter = getPatternFormatter(pattern).withLocale(locale); 283 ParsePosition pos = new ParsePosition(0); 284 assertEquals(DayOfWeek.from(formatter.parse(input, pos)), expected); 285 assertEquals(pos.getIndex(), input.length()); 286 } 287 288 //----------------------------------------------------------------------- 289 @Test(dataProvider="parseText") 290 public void test_parse_strict_caseSensitive_parseUpper(TemporalField field, TextStyle style, int value, String input) throws Exception { 291 if (input.equals(input.toUpperCase(Locale.ROOT))) { 292 // Skip if the given input is all upper case (e.g., "Q1") 293 return; 294 } 295 setCaseSensitive(true); 296 ParsePosition pos = new ParsePosition(0); 297 getFormatter(field, style).parseUnresolved(input.toUpperCase(Locale.ROOT), pos); 298 assertEquals(pos.getErrorIndex(), 0); 299 } 300 301 @Test(dataProvider="parseText") 302 public void test_parse_strict_caseInsensitive_parseUpper(TemporalField field, TextStyle style, int value, String input) throws Exception { 303 setCaseSensitive(false); 304 ParsePosition pos = new ParsePosition(0); 305 assertEquals(getFormatter(field, style).parseUnresolved(input.toUpperCase(Locale.ROOT), pos).getLong(field), (long) value); 306 assertEquals(pos.getIndex(), input.length()); 307 } 308 309 //----------------------------------------------------------------------- 310 @Test(dataProvider="parseText") 311 public void test_parse_strict_caseSensitive_parseLower(TemporalField field, TextStyle style, int value, String input) throws Exception { 312 if (input.equals(input.toLowerCase(Locale.ROOT))) { 313 // Skip if the given input is all lower case (e.g., "1st quarter") 314 return; 315 } 316 setCaseSensitive(true); 317 ParsePosition pos = new ParsePosition(0); 318 getFormatter(field, style).parseUnresolved(input.toLowerCase(Locale.ROOT), pos); 319 assertEquals(pos.getErrorIndex(), 0); 320 } 321 322 @Test(dataProvider="parseText") 323 public void test_parse_strict_caseInsensitive_parseLower(TemporalField field, TextStyle style, int value, String input) throws Exception { 324 setCaseSensitive(false); 325 ParsePosition pos = new ParsePosition(0); 326 assertEquals(getFormatter(field, style).parseUnresolved(input.toLowerCase(Locale.ROOT), pos).getLong(field), (long) value); 327 assertEquals(pos.getIndex(), input.length()); 328 } 329 330 //----------------------------------------------------------------------- 331 //----------------------------------------------------------------------- 332 //----------------------------------------------------------------------- 333 public void test_parse_full_strict_full_match() throws Exception { 334 setStrict(true); 335 ParsePosition pos = new ParsePosition(0); 336 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.FULL).parseUnresolved("January", pos).getLong(MONTH_OF_YEAR), 1L); 337 assertEquals(pos.getIndex(), 7); 338 } 339 340 public void test_parse_full_strict_short_noMatch() throws Exception { 341 setStrict(true); 342 ParsePosition pos = new ParsePosition(0); 343 getFormatter(MONTH_OF_YEAR, TextStyle.FULL).parseUnresolved("Janua", pos); 344 assertEquals(pos.getErrorIndex(), 0); 345 } 346 347 public void test_parse_full_strict_number_noMatch() throws Exception { 348 setStrict(true); 349 ParsePosition pos = new ParsePosition(0); 350 getFormatter(MONTH_OF_YEAR, TextStyle.FULL).parseUnresolved("1", pos); 351 assertEquals(pos.getErrorIndex(), 0); 352 } 353 354 //----------------------------------------------------------------------- 355 public void test_parse_short_strict_full_match() throws Exception { 356 setStrict(true); 357 ParsePosition pos = new ParsePosition(0); 358 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).parseUnresolved("January", pos).getLong(MONTH_OF_YEAR), 1L); 359 assertEquals(pos.getIndex(), 3); 360 } 361 362 public void test_parse_short_strict_short_match() throws Exception { 363 setStrict(true); 364 ParsePosition pos = new ParsePosition(0); 365 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).parseUnresolved("Janua", pos).getLong(MONTH_OF_YEAR), 1L); 366 assertEquals(pos.getIndex(), 3); 367 } 368 369 public void test_parse_short_strict_number_noMatch() throws Exception { 370 setStrict(true); 371 ParsePosition pos = new ParsePosition(0); 372 getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).parseUnresolved("1", pos); 373 assertEquals(pos.getErrorIndex(), 0); 374 } 375 376 //----------------------------------------------------------------------- 377 public void test_parse_french_short_strict_full_noMatch() throws Exception { 378 setStrict(true); 379 ParsePosition pos = new ParsePosition(0); 380 getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH) 381 .parseUnresolved("janvier", pos); 382 assertEquals(pos.getErrorIndex(), 0); 383 } 384 385 public void test_parse_french_short_strict_short_match() throws Exception { 386 setStrict(true); 387 ParsePosition pos = new ParsePosition(0); 388 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH) 389 .parseUnresolved("janv.", pos) 390 .getLong(MONTH_OF_YEAR), 391 1L); 392 assertEquals(pos.getIndex(), 5); 393 } 394 395 //----------------------------------------------------------------------- 396 public void test_parse_full_lenient_full_match() throws Exception { 397 setStrict(false); 398 ParsePosition pos = new ParsePosition(0); 399 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.FULL).parseUnresolved("January.", pos).getLong(MONTH_OF_YEAR), 1L); 400 assertEquals(pos.getIndex(), 7); 401 } 402 403 public void test_parse_full_lenient_short_match() throws Exception { 404 setStrict(false); 405 ParsePosition pos = new ParsePosition(0); 406 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.FULL).parseUnresolved("Janua", pos).getLong(MONTH_OF_YEAR), 1L); 407 assertEquals(pos.getIndex(), 3); 408 } 409 410 public void test_parse_full_lenient_number_match() throws Exception { 411 setStrict(false); 412 ParsePosition pos = new ParsePosition(0); 413 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.FULL).parseUnresolved("1", pos).getLong(MONTH_OF_YEAR), 1L); 414 assertEquals(pos.getIndex(), 1); 415 } 416 417 //----------------------------------------------------------------------- 418 public void test_parse_short_lenient_full_match() throws Exception { 419 setStrict(false); 420 ParsePosition pos = new ParsePosition(0); 421 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).parseUnresolved("January", pos).getLong(MONTH_OF_YEAR), 1L); 422 assertEquals(pos.getIndex(), 7); 423 } 424 425 public void test_parse_short_lenient_short_match() throws Exception { 426 setStrict(false); 427 ParsePosition pos = new ParsePosition(0); 428 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).parseUnresolved("Janua", pos).getLong(MONTH_OF_YEAR), 1L); 429 assertEquals(pos.getIndex(), 3); 430 } 431 432 public void test_parse_short_lenient_number_match() throws Exception { 433 setStrict(false); 434 ParsePosition pos = new ParsePosition(0); 435 assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).parseUnresolved("1", pos).getLong(MONTH_OF_YEAR), 1L); 436 assertEquals(pos.getIndex(), 1); 437 } 438 439 @Test(dataProvider="parseLenientText") 440 public void test_parseLenientText(Locale locale, TemporalField field, int expectedValue, String input) { 441 setStrict(false); 442 ParsePosition pos = new ParsePosition(0); 443 DateTimeFormatter formatter = getFormatter(field).withLocale(locale); 444 assertEquals(formatter.parseUnresolved(input, pos).getLong(field), (long) expectedValue); 445 assertEquals(pos.getIndex(), input.length()); 446 } 447 448 //----------------------------------------------------------------------- 449 @DataProvider(name="parseChronoLocalDate") 450 Object[][] provider_chronoLocalDate() { 451 return new Object[][] { 452 { HijrahDate.now() }, 453 { JapaneseDate.now() }, 454 { MinguoDate.now() }, 455 { ThaiBuddhistDate.now() }}; 456 } 457 458 private static final DateTimeFormatter fmt_chrono = 459 new DateTimeFormatterBuilder() 460 .optionalStart() 461 .appendChronologyId() 462 .appendLiteral(' ') 463 .optionalEnd() 464 .optionalStart() 465 .appendText(ChronoField.ERA, TextStyle.SHORT) 466 .appendLiteral(' ') 467 .optionalEnd() 468 .appendValue(ChronoField.YEAR_OF_ERA, 1, 9, SignStyle.NORMAL) 469 .appendLiteral('-') 470 .appendValue(ChronoField.MONTH_OF_YEAR, 1, 2, SignStyle.NEVER) 471 .appendLiteral('-') 472 .appendValue(ChronoField.DAY_OF_MONTH, 1, 2, SignStyle.NEVER) 473 .toFormatter(); 474 475 @Test(dataProvider="parseChronoLocalDate") 476 public void test_chronoLocalDate(ChronoLocalDate date) throws Exception { 477 System.out.printf(" %s, [fmt=%s]%n", date, fmt_chrono.format(date)); 478 assertEquals(date, fmt_chrono.parse(fmt_chrono.format(date), ChronoLocalDate::from)); 479 480 DateTimeFormatter fmt = DateTimeFormatter.ofPattern("[GGG ]yyy-MM-dd") 481 .withChronology(date.getChronology()); 482 System.out.printf(" %s, [fmt=%s]%n", date.toString(), fmt.format(date)); 483 assertEquals(date, fmt.parse(fmt.format(date), ChronoLocalDate::from)); 484 } 485 486 }