--- old/test/jdk/java/time/test/java/time/format/TestDateTimeFormatter.java 2018-04-18 13:12:14.962702500 +0530 +++ new/test/jdk/java/time/test/java/time/format/TestDateTimeFormatter.java 2018-04-18 13:12:12.315173100 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2018, 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 @@ -93,10 +93,11 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; /** * Test DateTimeFormatter. - * @bug 8085887 + * @bug 8085887 8193877 */ @Test public class TestDateTimeFormatter { @@ -272,4 +273,36 @@ } + @DataProvider(name = "validPatterns") + Object[][] valid_Data() { + return new Object[][]{ + {"pdQ", LocalDate.of(2018, 4, 9), "92"}, + {"ppdM", LocalDate.of(2018, 4, 9), " 94"}, + {"dppMyy", LocalDate.of(2018, 4, 9), "9 418"}, + {"ppHmmss", LocalTime.of(1,20,45), " 12045"}, + {"pppddMMyyyy", LocalDate.of(2018, 4, 9), " 09042018"}, + {"ppdppMYYYY", LocalDate.of(2018, 4, 9), " 9 42018"} + }; + } + + @Test(dataProvider="validPatterns") + public void test_pattern(String pattern, TemporalAccessor input, String expected) throws Exception { + String actual = DateTimeFormatter.ofPattern(pattern).format(input); + assertEquals(actual, expected); + } + + @DataProvider(name = "invalidPatterns") + Object[][] invalid_Data() { + return new Object[][]{ + {"pddQ", LocalDate.of(2018, 4, 9)}, + {"dpMMyy", LocalDate.of(2018, 4, 9)}, + {"H:pmmss", LocalTime.of(1,20,45)}, + }; + } + + @Test(dataProvider="invalidPatterns", expectedExceptions=DateTimeException.class) + public void test_invalidPattern(String pattern, TemporalAccessor input) throws Exception { + DateTimeFormatter.ofPattern(pattern).format(input); + } + }