微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.time.format.SignStyle的实例源码

项目:jdk8u-jdk    文件TCKSignStyle.java   
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate,SignStyle style,Class<?> expectedEx,String expectedStr) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR,2,4,style)
                                         .toFormatter();
    formatter = formatter.withZone(ZoneOffset.UTC);
    if (expectedEx == null) {
        String output = formatter.format(localDate);
        assertEquals(output,expectedStr);
    } else {
        try {
            formatter.format(localDate);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isinstance(ex));
        }
    }
}
项目:jdk8u-jdk    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_NOT_NEGATIVE(int minPad,int maxPad,long value,String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH,minPad,maxPad,SignStyle.NOT_NEGATIVE).formatTo(new MockFieldValue(DAY_OF_MONTH,value),buf);
        if (result == null || value < 0) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(),result);
    } catch (DateTimeException ex) {
        if (result == null || value < 0) {
            assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()),true);
        } else {
            throw ex;
        }
    }
}
项目:jdk8u-jdk    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_EXCEEDS_PAD(int minPad,SignStyle.EXCEEDS_PAD).formatTo(new MockFieldValue(DAY_OF_MONTH,buf);
        if (result == null) {
            fail("Expected exception");
            return;  // unreachable
        }
        if (result.length() > minPad || value < 0) {
            result = (value < 0 ? "-" + result : "+" + result);
        }
        assertEquals(buf.toString(),result);
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()),true);
    }
}
项目:jdk8u-jdk    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_fresh(int minWidth,int maxWidth,SignStyle signStyle,int subsequentWidth,String text,int pos,int expectedPos,long expectedValue) {
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatter dtf = getFormatter(DAY_OF_MONTH,minWidth,maxWidth,signStyle);
    if (subsequentWidth > 0) {
        // hacky,to reserve space
        dtf = builder.appendValue(DAY_OF_YEAR,subsequentWidth).toFormatter(locale).withDecimalStyle(decimalStyle);
    }
    TemporalAccessor parsed = dtf.parseUnresolved(text,ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(),expectedPos);
    } else {
        assertTrue(subsequentWidth >= 0);
        assertEquals(ppos.getIndex(),expectedPos + subsequentWidth);
        assertEquals(parsed.getLong(DAY_OF_MONTH),expectedValue);
        assertEquals(parsed.query(TemporalQueries.chronology()),null);
        assertEquals(parsed.query(TemporalQueries.zoneId()),null);
    }
}
项目:jdk8u-jdk    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_textField(int minWidth,long expectedValue) {
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatter dtf = getFormatter(DAY_OF_WEEK,expectedPos + subsequentWidth);
        assertEquals(parsed.getLong(DAY_OF_WEEK),null);
    }
}
项目:jdk8u-jdk    文件TestNumberParser.java   
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input,int parseLen,Integer parseMonth,Integer parsedDay) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    DateTimeFormatter f = builder
            .appendValue(MONTH_OF_YEAR,1,SignStyle.norMAL)
            .appendValue(DAY_OF_MONTH,2).toFormatter(locale).withDecimalStyle(decimalStyle);
    TemporalAccessor parsed = f.parseUnresolved(input,pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(),parseLen);
    } else {
        assertEquals(pos.getIndex(),parseLen);
        assertEquals(parsed.getLong(MONTH_OF_YEAR),(long) parseMonth);
        assertEquals(parsed.getLong(DAY_OF_MONTH),(long) parsedDay);
        assertEquals(parsed.query(TemporalQueries.chronology()),null);
    }
}
项目:openjdk-jdk10    文件TCKSignStyle.java   
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate,expectedStr);
    } else {
        try {
            formatter.format(localDate);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isinstance(ex));
        }
    }
}
项目:openjdk-jdk10    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_NOT_NEGATIVE(int minPad,true);
        } else {
            throw ex;
        }
    }
}
项目:openjdk-jdk10    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_EXCEEDS_PAD(int minPad,true);
    }
}
项目:openjdk-jdk10    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_fresh(int minWidth,null);
    }
}
项目:openjdk-jdk10    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_textField(int minWidth,null);
    }
}
项目:openjdk-jdk10    文件TestNumberParser.java   
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input,null);
    }
}
项目:openjdk9    文件TCKSignStyle.java   
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate,expectedStr);
    } else {
        try {
            formatter.format(localDate);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isinstance(ex));
        }
    }
}
项目:openjdk9    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_NOT_NEGATIVE(int minPad,true);
        } else {
            throw ex;
        }
    }
}
项目:openjdk9    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_EXCEEDS_PAD(int minPad,true);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_NOT_NEGATIVE(int minPad,true);
        } else {
            throw ex;
        }
    }
}
项目:openjdk9    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_fresh(int minWidth,null);
    }
}
项目:openjdk9    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_textField(int minWidth,null);
    }
}
项目:jdk8u_jdk    文件TCKSignStyle.java   
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate,expectedStr);
    } else {
        try {
            formatter.format(localDate);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isinstance(ex));
        }
    }
}
项目:jdk8u_jdk    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_NOT_NEGATIVE(int minPad,true);
        } else {
            throw ex;
        }
    }
}
项目:jdk8u_jdk    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_EXCEEDS_PAD(int minPad,true);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_fresh(int minWidth,null);
    }
}
项目:jdk8u_jdk    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_fresh(int minWidth,null);
    }
}
项目:jdk8u_jdk    文件TestNumberParser.java   
@Test(dataProvider="parseData")
public void test_parse_textField(int minWidth,null);
    }
}
项目:jdk8u-jdk    文件TCKPadPrinterParser.java   
@Test(dataProvider="parseStrict")
public void test_parseStrict(String text,int expectedindex,int expectedErrorIndex,Number expectedMonth) {
    builder.padNext(3,'#').appendValue(MONTH_OF_YEAR,3,SignStyle.norMAL);
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text,pos);
    assertEquals(pos.getIndex(),expectedindex);
    assertEquals(pos.getErrorIndex(),expectedErrorIndex);
    if (expectedMonth != null) {
        assertEquals(parsed.isSupported(MONTH_OF_YEAR),true);
        assertEquals(parsed.getLong(MONTH_OF_YEAR),expectedMonth.longValue());
    } else {
        assertEquals(parsed,null);
    }
}
项目:jdk8u-jdk    文件TCKPadPrinterParser.java   
@Test(dataProvider="parseLenient")
public void test_parseLenient(String text,Number expectedMonth) {
    builder.parseLenient().padNext(3,null);
    }
}
项目:jdk8u-jdk    文件TCKPadPrinterParser.java   
@Test
public void test_parse_decoratedStartsWithPad_number() {
    builder.padNext(3,'-').appendValue(MONTH_OF_YEAR,SignStyle.norMAL);
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved("--2",3);
    assertEquals(pos.getErrorIndex(),-1);
    assertEquals(parsed.isSupported(MONTH_OF_YEAR),true);
    assertEquals(parsed.getLong(MONTH_OF_YEAR),2L);  // +2,not -2
}
项目:jdk8u-jdk    文件TCKSignStyle.java   
@DataProvider(name="signStyle")
Object[][] data_signStyle() {
    return new Object[][] {
            {LocalDate.of(0,10,2),SignStyle.ALWAYS,null,"+00"},{LocalDate.of(2001,"+2001"},{LocalDate.of(-2001,"-2001"},SignStyle.norMAL,"2001"},SignStyle.NEVER,SignStyle.NOT_NEGATIVE,DateTimeException.class,""},{LocalDate.of(0,SignStyle.EXCEEDS_PAD,"00"},{LocalDate.of(1,"01"},{LocalDate.of(-1,"-01"},{LocalDate.of(20001,};
}
项目:jdk8u-jdk    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_NEVER(int minPad,SignStyle.NEVER).formatTo(new MockFieldValue(DAY_OF_MONTH,buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(),true);
    }
}
项目:jdk8u-jdk    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_norMAL(int minPad,SignStyle.norMAL).formatTo(new MockFieldValue(DAY_OF_MONTH,(value < 0 ? "-" + result : result));
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()),true);
    }
}
项目:jdk8u-jdk    文件TestNumberPrinter.java   
@Test(dataProvider="Pad")
public void test_pad_ALWAYS(int minPad,SignStyle.ALWAYS).formatTo(new MockFieldValue(DAY_OF_MONTH,(value < 0 ? "-" + result : "+" + result));
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()),true);
    }
}
项目:jdk8u-jdk    文件TestDateTimeFormatter.java   
@Test
public void test_withLocale_same() throws Exception {
    DateTimeFormatter base =
        new DateTimeFormatterBuilder().appendLiteral("ONE")
                                      .appendValue(DAY_OF_MONTH,SignStyle.NOT_NEGATIVE)
                                      .toFormatter(Locale.ENGLISH)
                                      .withDecimalStyle(DecimalStyle.STANDARD);
    DateTimeFormatter test = base.withLocale(Locale.ENGLISH);
    assertSame(test,base);
}
项目:jdk8u-jdk    文件TestDateTimeFormatterBuilder.java   
@Test
public void test_appendValue_subsequent2_parse3() throws Exception {
    builder.appendValue(MONTH_OF_YEAR,SignStyle.norMAL).appendValue(DAY_OF_MONTH,2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(),"Value(MonthOfYear,norMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("123",new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR),1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH),23L);
}
项目:jdk8u-jdk    文件TestDateTimeFormatterBuilder.java   
@Test
public void test_appendValue_subsequent2_parse4() throws Exception {
    builder.appendValue(MONTH_OF_YEAR,2)");
    TemporalAccessor parsed = f.parseUnresolved("0123",23L);
}
项目:jdk8u-jdk    文件TestDateTimeFormatterBuilder.java   
@Test
public void test_appendValue_subsequent2_parse5() throws Exception {
    builder.appendValue(MONTH_OF_YEAR,2).appendLiteral('4');
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(),2)'4'");
    TemporalAccessor parsed = f.parseUnresolved("01234",23L);
}
项目:jdk8u-jdk    文件TestDateTimeFormatterBuilder.java   
@Test
public void test_appendValue_subsequent3_parse6() throws Exception {
    builder
        .appendValue(YEAR,SignStyle.EXCEEDS_PAD)
        .appendValue(MONTH_OF_YEAR,2)
        .appendValue(DAY_OF_MONTH,"Value(Year,EXCEEDS_PAD)Value(MonthOfYear,2)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("20090630",new ParsePosition(0));
    assertEquals(parsed.getLong(YEAR),2009L);
    assertEquals(parsed.getLong(MONTH_OF_YEAR),6L);
    assertEquals(parsed.getLong(DAY_OF_MONTH),30L);
}
项目:jdk8u-jdk    文件TestDateTimeFormatterBuilder.java   
@Test
public void test_appendValueReduced_subsequent_parse() throws Exception {
    builder.appendValue(MONTH_OF_YEAR,SignStyle.norMAL).appendValueReduced(YEAR,2000);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(),norMAL)ReducedValue(Year,2000)");
    ParsePosition ppos = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("123",ppos);
    assertNotNull(parsed,"Parse Failed: " + ppos.toString());
    assertEquals(parsed.getLong(MONTH_OF_YEAR),1L);
    assertEquals(parsed.getLong(YEAR),2023L);
}
项目:jdk8u-jdk    文件TestNumberParser.java   
@DataProvider(name="error")
Object[][] data_error() {
    return new Object[][] {
        {DAY_OF_MONTH,"12",-1,indexoutofboundsexception.class},{DAY_OF_MONTH,};
}
项目:jdk8u-jdk    文件TestNumberParser.java   
@Test(dataProvider="error")
public void test_parse_error(TemporalField field,int min,int max,Class<?> expected) {
    try {
        getFormatter(field,min,max,style).parseUnresolved(text,new ParsePosition(pos));
        fail();
    } catch (RuntimeException ex) {
        assertTrue(expected.isinstance(ex));
    }
}
项目:jdk8u-jdk    文件TestNumberParser.java   
@Test(dataProvider="parseSignsstrict")
public void test_parseSignsstrict(String input,Integer parseVal) throws Exception {
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(DAY_OF_MONTH,style).parseUnresolved(input,parseLen);
        assertEquals(parsed.getLong(DAY_OF_MONTH),(long)parseVal);
        assertEquals(parsed.query(TemporalQueries.chronology()),null);
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。