test/jdk/java/time/test/java/time/format/TestFractionPrinterParser.java
changeset 58086 d52f77f0acb5
parent 47216 71c04702a3d5
equal deleted inserted replaced
58084:cddef3bde924 58086:d52f77f0acb5
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    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.
    58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    59  */
    59  */
    60 package test.java.time.format;
    60 package test.java.time.format;
    61 
    61 
       
    62 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
    62 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
    63 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
    63 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
    64 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
    64 import static org.testng.Assert.assertEquals;
    65 import static org.testng.Assert.assertEquals;
    65 import static org.testng.Assert.fail;
    66 import static org.testng.Assert.fail;
    66 
    67 
    75 import org.testng.annotations.Test;
    76 import org.testng.annotations.Test;
    76 import test.java.time.temporal.MockFieldValue;
    77 import test.java.time.temporal.MockFieldValue;
    77 
    78 
    78 /**
    79 /**
    79  * Test FractionPrinterParser.
    80  * Test FractionPrinterParser.
       
    81  *
       
    82  * @bug 8230136
    80  */
    83  */
    81 @Test
    84 @Test
    82 public class TestFractionPrinterParser extends AbstractTestPrinterParser {
    85 public class TestFractionPrinterParser extends AbstractTestPrinterParser {
    83 
    86 
    84     private DateTimeFormatter getFormatter(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
    87     private DateTimeFormatter getFormatter(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
   329         TemporalAccessor parsed = getFormatter(field, min, max, decimalPoint).parseUnresolved(text, ppos);
   332         TemporalAccessor parsed = getFormatter(field, min, max, decimalPoint).parseUnresolved(text, ppos);
   330         assertEquals(ppos.getErrorIndex(), expected);
   333         assertEquals(ppos.getErrorIndex(), expected);
   331         assertEquals(parsed, null);
   334         assertEquals(parsed, null);
   332     }
   335     }
   333 
   336 
       
   337     @DataProvider(name="ParseMinWidth")
       
   338     Object[][] provider_parseMinWidth() {
       
   339         return new Object[][] {
       
   340             {MILLI_OF_SECOND, 3, 3, true, ".1x"},
       
   341             {MILLI_OF_SECOND, 3, 3, true, ".12x"},
       
   342             {MILLI_OF_SECOND, 3, 3, true, ".1234x"},
       
   343         };
       
   344     }
       
   345 
       
   346     @Test(dataProvider="ParseMinWidth", expectedExceptions=DateTimeException.class)
       
   347     public void test_parse_minWidth(TemporalField field, int min, int max, boolean decimalPoint, String text) throws Exception {
       
   348         builder
       
   349             .appendFraction(field, min, max, decimalPoint)
       
   350             .appendLiteral("x")
       
   351             .toFormatter(locale)
       
   352             .parse(text);
       
   353     }
       
   354 
   334     //-----------------------------------------------------------------------
   355     //-----------------------------------------------------------------------
   335     public void test_toString() throws Exception {
   356     public void test_toString() throws Exception {
   336         assertEquals(getFormatter(NANO_OF_SECOND, 3, 6, true).toString(), "Fraction(NanoOfSecond,3,6,DecimalPoint)");
   357         assertEquals(getFormatter(NANO_OF_SECOND, 3, 6, true).toString(), "Fraction(NanoOfSecond,3,6,DecimalPoint)");
   337     }
   358     }
   338 
   359