test/java/time/test/java/time/format/TestFractionPrinterParser.java

Print this page




  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 java.time.format.*;
  63 
  64 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  65 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  66 import static org.testng.Assert.assertEquals;
  67 import static org.testng.Assert.fail;
  68 
  69 import java.text.ParsePosition;
  70 import java.time.DateTimeException;
  71 import java.time.LocalTime;
  72 import java.time.format.DateTimeBuilder;

  73 import java.time.temporal.TemporalField;
  74 
  75 import test.java.time.temporal.MockFieldValue;
  76 
  77 import org.testng.annotations.DataProvider;
  78 import org.testng.annotations.Test;

  79 
  80 /**
  81  * Test FractionPrinterParser.
  82  */
  83 @Test(groups={"implementation"})
  84 public class TestFractionPrinterParser extends AbstractTestPrinterParser {
  85 
  86     private DateTimeFormatter getFormatter(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
  87         return builder.appendFraction(field, minWidth, maxWidth, decimalPoint).toFormatter(locale).withSymbols(symbols);
  88     }
  89 
  90     //-----------------------------------------------------------------------
  91     // print
  92     //-----------------------------------------------------------------------
  93     @Test(expectedExceptions=DateTimeException.class)
  94     public void test_print_emptyCalendrical() throws Exception {
  95         getFormatter(NANO_OF_SECOND, 0, 9, true).printTo(EMPTY_DTA, buf);
  96     }
  97 
  98     public void test_print_append() throws Exception {
  99         buf.append("EXISTING");
 100         getFormatter(NANO_OF_SECOND, 0, 9, true).printTo(LocalTime.of(12, 30, 40, 3), buf);
 101         assertEquals(buf.toString(), "EXISTING.000000003");
 102     }
 103 
 104     //-----------------------------------------------------------------------
 105     @DataProvider(name="Nanos")
 106     Object[][] provider_nanos() {
 107         return new Object[][] {
 108             {0, 9, 0,           ""},
 109             {0, 9, 2,           ".000000002"},
 110             {0, 9, 20,          ".00000002"},
 111             {0, 9, 200,         ".0000002"},
 112             {0, 9, 2000,        ".000002"},
 113             {0, 9, 20000,       ".00002"},
 114             {0, 9, 200000,      ".0002"},
 115             {0, 9, 2000000,     ".002"},
 116             {0, 9, 20000000,    ".02"},
 117             {0, 9, 200000000,   ".2"},
 118             {0, 9, 1,           ".000000001"},
 119             {0, 9, 12,          ".000000012"},
 120             {0, 9, 123,         ".000000123"},


 163             {6, 6, 2000,        ".000002"},
 164             {6, 6, 20000,       ".000020"},
 165             {6, 6, 200000,      ".000200"},
 166             {6, 6, 2000000,     ".002000"},
 167             {6, 6, 20000000,    ".020000"},
 168             {6, 6, 200000000,   ".200000"},
 169             {6, 6, 1,           ".000000"},
 170             {6, 6, 12,          ".000000"},
 171             {6, 6, 123,         ".000000"},
 172             {6, 6, 1234,        ".000001"},
 173             {6, 6, 12345,       ".000012"},
 174             {6, 6, 123456,      ".000123"},
 175             {6, 6, 1234567,     ".001234"},
 176             {6, 6, 12345678,    ".012345"},
 177             {6, 6, 123456789,   ".123456"},
 178        };
 179     }
 180 
 181     @Test(dataProvider="Nanos")
 182     public void test_print_nanos(int minWidth, int maxWidth, int value, String result) throws Exception {
 183         getFormatter(NANO_OF_SECOND,  minWidth, maxWidth, true).printTo(new MockFieldValue(NANO_OF_SECOND, value), buf);
 184         if (result == null) {
 185             fail("Expected exception");
 186         }
 187         assertEquals(buf.toString(), result);
 188     }
 189 
 190     @Test(dataProvider="Nanos")
 191     public void test_print_nanos_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
 192         getFormatter(NANO_OF_SECOND,  minWidth, maxWidth, false).printTo(new MockFieldValue(NANO_OF_SECOND, value), buf);
 193         if (result == null) {
 194             fail("Expected exception");
 195         }
 196         assertEquals(buf.toString(), (result.startsWith(".") ? result.substring(1) : result));
 197     }
 198 
 199     //-----------------------------------------------------------------------
 200     @DataProvider(name="Seconds")
 201     Object[][] provider_seconds() {
 202         return new Object[][] {
 203             {0, 9, 0,  ""},
 204             {0, 9, 3,  ".05"},
 205             {0, 9, 6,  ".1"},
 206             {0, 9, 9,  ".15"},
 207             {0, 9, 12, ".2"},
 208             {0, 9, 15, ".25"},
 209             {0, 9, 30, ".5"},
 210             {0, 9, 45, ".75"},
 211 
 212             {2, 2, 0,  ".00"},
 213             {2, 2, 3,  ".05"},
 214             {2, 2, 6,  ".10"},
 215             {2, 2, 9,  ".15"},
 216             {2, 2, 12, ".20"},
 217             {2, 2, 15, ".25"},
 218             {2, 2, 30, ".50"},
 219             {2, 2, 45, ".75"},
 220         };
 221     }
 222 
 223     @Test(dataProvider="Seconds")
 224     public void test_print_seconds(int minWidth, int maxWidth, int value, String result) throws Exception {
 225         getFormatter(SECOND_OF_MINUTE, minWidth, maxWidth, true).printTo(new MockFieldValue(SECOND_OF_MINUTE, value), buf);
 226         if (result == null) {
 227             fail("Expected exception");
 228         }
 229         assertEquals(buf.toString(), result);
 230     }
 231 
 232     @Test(dataProvider="Seconds")
 233     public void test_print_seconds_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
 234         getFormatter(SECOND_OF_MINUTE, minWidth, maxWidth, false).printTo(new MockFieldValue(SECOND_OF_MINUTE, value), buf);
 235         if (result == null) {
 236             fail("Expected exception");
 237         }
 238         assertEquals(buf.toString(), (result.startsWith(".") ? result.substring(1) : result));
 239     }
 240 
 241     //-----------------------------------------------------------------------
 242     // parse
 243     //-----------------------------------------------------------------------
 244     @Test(dataProvider="Nanos")
 245     public void test_reverseParse(int minWidth, int maxWidth, int value, String result) throws Exception {
 246         ParsePosition pos = new ParsePosition(0);
 247         int expectedValue = fixParsedValue(maxWidth, value);
 248         DateTimeBuilder dtb = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, true).parseToBuilder(result, pos);
 249         assertEquals(pos.getIndex(), result.length());
 250         assertParsed(dtb, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 251     }
 252 
 253     @Test(dataProvider="Nanos")
 254     public void test_reverseParse_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
 255         ParsePosition pos = new ParsePosition((result.startsWith(".") ? 1 : 0));
 256         DateTimeBuilder dtb = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, false).parseToBuilder(result, pos);
 257         assertEquals(pos.getIndex(), result.length());
 258         int expectedValue = fixParsedValue(maxWidth, value);
 259         assertParsed(dtb, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 260     }
 261 
 262     @Test(dataProvider="Nanos")
 263     public void test_reverseParse_followedByNonDigit(int minWidth, int maxWidth, int value, String result) throws Exception {
 264         ParsePosition pos = new ParsePosition(0);
 265         int expectedValue = fixParsedValue(maxWidth, value);
 266         DateTimeBuilder dtb = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, true).parseToBuilder(result + " ", pos);
 267         assertEquals(pos.getIndex(), result.length());
 268         assertParsed(dtb, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 269     }
 270 
 271 //    @Test(dataProvider="Nanos")
 272 //    public void test_reverseParse_followedByNonDigit_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
 273 //        FractionPrinterParser pp = new FractionPrinterParser(NANO_OF_SECOND, minWidth, maxWidth, false);
 274 //        int newPos = pp.parse(parseContext, result + " ", (result.startsWith(".") ? 1 : 0));
 275 //        assertEquals(newPos, result.length());
 276 //        int expectedValue = fixParsedValue(maxWidth, value);
 277 //        assertParsed(parseContext, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 278 //    }
 279 
 280     @Test(dataProvider="Nanos")
 281     public void test_reverseParse_preceededByNonDigit(int minWidth, int maxWidth, int value, String result) throws Exception {
 282         ParsePosition pos = new ParsePosition(1);
 283         int expectedValue = fixParsedValue(maxWidth, value);
 284         DateTimeBuilder dtb = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, true).parseToBuilder(" " + result, pos);
 285         assertEquals(pos.getIndex(), result.length() + 1);
 286         assertParsed(dtb, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 287     }
 288 
 289     private int fixParsedValue(int maxWidth, int value) {
 290         if (maxWidth < 9) {
 291             int power = (int) Math.pow(10, (9 - maxWidth));
 292             value = (value / power) * power;
 293         }
 294         return value;
 295     }
 296 
 297     @Test(dataProvider="Seconds")
 298     public void test_reverseParse_seconds(int minWidth, int maxWidth, int value, String result) throws Exception {
 299         ParsePosition pos = new ParsePosition(0);
 300         DateTimeBuilder dtb = getFormatter(SECOND_OF_MINUTE, minWidth, maxWidth, true).parseToBuilder(result, pos);
 301         assertEquals(pos.getIndex(), result.length());
 302         assertParsed(dtb, SECOND_OF_MINUTE, value == 0 && minWidth == 0 ? null : (long) value);
 303     }
 304 
 305     private void assertParsed(DateTimeBuilder dtb, TemporalField field, Long value) {
 306         if (value == null) {
 307             assertEquals(dtb.containsFieldValue(field), false);
 308         } else {
 309             assertEquals(dtb.getLong(field), (long)value);

 310         }
 311     }
 312 
 313     //-----------------------------------------------------------------------
 314     @DataProvider(name="ParseNothing")
 315     Object[][] provider_parseNothing() {
 316         return new Object[][] {
 317             {NANO_OF_SECOND, 3, 6, true, "", 0, 0},
 318             {NANO_OF_SECOND, 3, 6, true, "A", 0, 0},
 319             {NANO_OF_SECOND, 3, 6, true, ".", 0, 1},
 320             {NANO_OF_SECOND, 3, 6, true, ".5", 0, 1},
 321             {NANO_OF_SECOND, 3, 6, true, ".51", 0, 1},
 322             {NANO_OF_SECOND, 3, 6, true, ".A23456", 0, 1},
 323             {NANO_OF_SECOND, 3, 6, true, ".1A3456", 0, 1},
 324         };
 325     }
 326 
 327     @Test(dataProvider = "ParseNothing")
 328     public void test_parse_nothing(TemporalField field, int min, int max, boolean decimalPoint, String text, int pos, int expected) {
 329         ParsePosition ppos = new ParsePosition(pos);
 330         DateTimeBuilder dtb = getFormatter(field, min, max, decimalPoint).parseToBuilder(text, ppos);
 331         assertEquals(ppos.getErrorIndex(), expected);

 332     }
 333 
 334     //-----------------------------------------------------------------------
 335     public void test_toString() throws Exception {
 336         assertEquals(getFormatter(NANO_OF_SECOND, 3, 6, true).toString(), "Fraction(NanoOfSecond,3,6,DecimalPoint)");
 337     }
 338 
 339     public void test_toString_noDecimalPoint() throws Exception {
 340         assertEquals(getFormatter(NANO_OF_SECOND, 3, 6, false).toString(), "Fraction(NanoOfSecond,3,6)");
 341     }
 342 
 343 }


  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.NANO_OF_SECOND;
  63 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  64 import static org.testng.Assert.assertEquals;
  65 import static org.testng.Assert.fail;
  66 
  67 import java.text.ParsePosition;
  68 import java.time.DateTimeException;
  69 import java.time.LocalTime;
  70 import java.time.format.DateTimeFormatter;
  71 import java.time.temporal.TemporalAccessor;
  72 import java.time.temporal.TemporalField;
  73 


  74 import org.testng.annotations.DataProvider;
  75 import org.testng.annotations.Test;
  76 import test.java.time.temporal.MockFieldValue;
  77 
  78 /**
  79  * Test FractionPrinterParser.
  80  */
  81 @Test(groups={"implementation"})
  82 public class TestFractionPrinterParser extends AbstractTestPrinterParser {
  83 
  84     private DateTimeFormatter getFormatter(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
  85         return builder.appendFraction(field, minWidth, maxWidth, decimalPoint).toFormatter(locale).withSymbols(symbols);
  86     }
  87 
  88     //-----------------------------------------------------------------------
  89     // print
  90     //-----------------------------------------------------------------------
  91     @Test(expectedExceptions=DateTimeException.class)
  92     public void test_print_emptyCalendrical() throws Exception {
  93         getFormatter(NANO_OF_SECOND, 0, 9, true).formatTo(EMPTY_DTA, buf);
  94     }
  95 
  96     public void test_print_append() throws Exception {
  97         buf.append("EXISTING");
  98         getFormatter(NANO_OF_SECOND, 0, 9, true).formatTo(LocalTime.of(12, 30, 40, 3), buf);
  99         assertEquals(buf.toString(), "EXISTING.000000003");
 100     }
 101 
 102     //-----------------------------------------------------------------------
 103     @DataProvider(name="Nanos")
 104     Object[][] provider_nanos() {
 105         return new Object[][] {
 106             {0, 9, 0,           ""},
 107             {0, 9, 2,           ".000000002"},
 108             {0, 9, 20,          ".00000002"},
 109             {0, 9, 200,         ".0000002"},
 110             {0, 9, 2000,        ".000002"},
 111             {0, 9, 20000,       ".00002"},
 112             {0, 9, 200000,      ".0002"},
 113             {0, 9, 2000000,     ".002"},
 114             {0, 9, 20000000,    ".02"},
 115             {0, 9, 200000000,   ".2"},
 116             {0, 9, 1,           ".000000001"},
 117             {0, 9, 12,          ".000000012"},
 118             {0, 9, 123,         ".000000123"},


 161             {6, 6, 2000,        ".000002"},
 162             {6, 6, 20000,       ".000020"},
 163             {6, 6, 200000,      ".000200"},
 164             {6, 6, 2000000,     ".002000"},
 165             {6, 6, 20000000,    ".020000"},
 166             {6, 6, 200000000,   ".200000"},
 167             {6, 6, 1,           ".000000"},
 168             {6, 6, 12,          ".000000"},
 169             {6, 6, 123,         ".000000"},
 170             {6, 6, 1234,        ".000001"},
 171             {6, 6, 12345,       ".000012"},
 172             {6, 6, 123456,      ".000123"},
 173             {6, 6, 1234567,     ".001234"},
 174             {6, 6, 12345678,    ".012345"},
 175             {6, 6, 123456789,   ".123456"},
 176        };
 177     }
 178 
 179     @Test(dataProvider="Nanos")
 180     public void test_print_nanos(int minWidth, int maxWidth, int value, String result) throws Exception {
 181         getFormatter(NANO_OF_SECOND,  minWidth, maxWidth, true).formatTo(new MockFieldValue(NANO_OF_SECOND, value), buf);
 182         if (result == null) {
 183             fail("Expected exception");
 184         }
 185         assertEquals(buf.toString(), result);
 186     }
 187 
 188     @Test(dataProvider="Nanos")
 189     public void test_print_nanos_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
 190         getFormatter(NANO_OF_SECOND,  minWidth, maxWidth, false).formatTo(new MockFieldValue(NANO_OF_SECOND, value), buf);
 191         if (result == null) {
 192             fail("Expected exception");
 193         }
 194         assertEquals(buf.toString(), (result.startsWith(".") ? result.substring(1) : result));
 195     }
 196 
 197     //-----------------------------------------------------------------------
 198     @DataProvider(name="Seconds")
 199     Object[][] provider_seconds() {
 200         return new Object[][] {
 201             {0, 9, 0,  ""},
 202             {0, 9, 3,  ".05"},
 203             {0, 9, 6,  ".1"},
 204             {0, 9, 9,  ".15"},
 205             {0, 9, 12, ".2"},
 206             {0, 9, 15, ".25"},
 207             {0, 9, 30, ".5"},
 208             {0, 9, 45, ".75"},
 209 
 210             {2, 2, 0,  ".00"},
 211             {2, 2, 3,  ".05"},
 212             {2, 2, 6,  ".10"},
 213             {2, 2, 9,  ".15"},
 214             {2, 2, 12, ".20"},
 215             {2, 2, 15, ".25"},
 216             {2, 2, 30, ".50"},
 217             {2, 2, 45, ".75"},
 218         };
 219     }
 220 
 221     @Test(dataProvider="Seconds")
 222     public void test_print_seconds(int minWidth, int maxWidth, int value, String result) throws Exception {
 223         getFormatter(SECOND_OF_MINUTE, minWidth, maxWidth, true).formatTo(new MockFieldValue(SECOND_OF_MINUTE, value), buf);
 224         if (result == null) {
 225             fail("Expected exception");
 226         }
 227         assertEquals(buf.toString(), result);
 228     }
 229 
 230     @Test(dataProvider="Seconds")
 231     public void test_print_seconds_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
 232         getFormatter(SECOND_OF_MINUTE, minWidth, maxWidth, false).formatTo(new MockFieldValue(SECOND_OF_MINUTE, value), buf);
 233         if (result == null) {
 234             fail("Expected exception");
 235         }
 236         assertEquals(buf.toString(), (result.startsWith(".") ? result.substring(1) : result));
 237     }
 238 
 239     //-----------------------------------------------------------------------
 240     // parse
 241     //-----------------------------------------------------------------------
 242     @Test(dataProvider="Nanos")
 243     public void test_reverseParse(int minWidth, int maxWidth, int value, String result) throws Exception {
 244         ParsePosition pos = new ParsePosition(0);
 245         int expectedValue = fixParsedValue(maxWidth, value);
 246         TemporalAccessor parsed = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, true).parseUnresolved(result, pos);
 247         assertEquals(pos.getIndex(), result.length());
 248         assertParsed(parsed, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 249     }
 250 
 251     @Test(dataProvider="Nanos")
 252     public void test_reverseParse_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
 253         ParsePosition pos = new ParsePosition((result.startsWith(".") ? 1 : 0));
 254         TemporalAccessor parsed = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, false).parseUnresolved(result, pos);
 255         assertEquals(pos.getIndex(), result.length());
 256         int expectedValue = fixParsedValue(maxWidth, value);
 257         assertParsed(parsed, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 258     }
 259 
 260     @Test(dataProvider="Nanos")
 261     public void test_reverseParse_followedByNonDigit(int minWidth, int maxWidth, int value, String result) throws Exception {
 262         ParsePosition pos = new ParsePosition(0);
 263         int expectedValue = fixParsedValue(maxWidth, value);
 264         TemporalAccessor parsed = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, true).parseUnresolved(result + " ", pos);
 265         assertEquals(pos.getIndex(), result.length());
 266         assertParsed(parsed, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 267     }
 268 
 269 //    @Test(dataProvider="Nanos")
 270 //    public void test_reverseParse_followedByNonDigit_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
 271 //        FractionPrinterParser pp = new FractionPrinterParser(NANO_OF_SECOND, minWidth, maxWidth, false);
 272 //        int newPos = pp.parse(parseContext, result + " ", (result.startsWith(".") ? 1 : 0));
 273 //        assertEquals(newPos, result.length());
 274 //        int expectedValue = fixParsedValue(maxWidth, value);
 275 //        assertParsed(parseContext, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 276 //    }
 277 
 278     @Test(dataProvider="Nanos")
 279     public void test_reverseParse_preceededByNonDigit(int minWidth, int maxWidth, int value, String result) throws Exception {
 280         ParsePosition pos = new ParsePosition(1);
 281         int expectedValue = fixParsedValue(maxWidth, value);
 282         TemporalAccessor parsed = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, true).parseUnresolved(" " + result, pos);
 283         assertEquals(pos.getIndex(), result.length() + 1);
 284         assertParsed(parsed, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
 285     }
 286 
 287     private int fixParsedValue(int maxWidth, int value) {
 288         if (maxWidth < 9) {
 289             int power = (int) Math.pow(10, (9 - maxWidth));
 290             value = (value / power) * power;
 291         }
 292         return value;
 293     }
 294 
 295     @Test(dataProvider="Seconds")
 296     public void test_reverseParse_seconds(int minWidth, int maxWidth, int value, String result) throws Exception {
 297         ParsePosition pos = new ParsePosition(0);
 298         TemporalAccessor parsed = getFormatter(SECOND_OF_MINUTE, minWidth, maxWidth, true).parseUnresolved(result, pos);
 299         assertEquals(pos.getIndex(), result.length());
 300         assertParsed(parsed, SECOND_OF_MINUTE, value == 0 && minWidth == 0 ? null : (long) value);
 301     }
 302 
 303     private void assertParsed(TemporalAccessor parsed, TemporalField field, Long value) {
 304         if (value == null) {
 305             assertEquals(parsed.isSupported(field), false);
 306         } else {
 307             assertEquals(parsed.isSupported(field), true);
 308             assertEquals(parsed.getLong(field), (long) value);
 309         }
 310     }
 311 
 312     //-----------------------------------------------------------------------
 313     @DataProvider(name="ParseNothing")
 314     Object[][] provider_parseNothing() {
 315         return new Object[][] {
 316             {NANO_OF_SECOND, 3, 6, true, "", 0, 0},
 317             {NANO_OF_SECOND, 3, 6, true, "A", 0, 0},
 318             {NANO_OF_SECOND, 3, 6, true, ".", 0, 1},
 319             {NANO_OF_SECOND, 3, 6, true, ".5", 0, 1},
 320             {NANO_OF_SECOND, 3, 6, true, ".51", 0, 1},
 321             {NANO_OF_SECOND, 3, 6, true, ".A23456", 0, 1},
 322             {NANO_OF_SECOND, 3, 6, true, ".1A3456", 0, 1},
 323         };
 324     }
 325 
 326     @Test(dataProvider = "ParseNothing")
 327     public void test_parse_nothing(TemporalField field, int min, int max, boolean decimalPoint, String text, int pos, int expected) {
 328         ParsePosition ppos = new ParsePosition(pos);
 329         TemporalAccessor parsed = getFormatter(field, min, max, decimalPoint).parseUnresolved(text, ppos);
 330         assertEquals(ppos.getErrorIndex(), expected);
 331         assertEquals(parsed, null);
 332     }
 333 
 334     //-----------------------------------------------------------------------
 335     public void test_toString() throws Exception {
 336         assertEquals(getFormatter(NANO_OF_SECOND, 3, 6, true).toString(), "Fraction(NanoOfSecond,3,6,DecimalPoint)");
 337     }
 338 
 339     public void test_toString_noDecimalPoint() throws Exception {
 340         assertEquals(getFormatter(NANO_OF_SECOND, 3, 6, false).toString(), "Fraction(NanoOfSecond,3,6)");
 341     }
 342 
 343 }