当前位置: 首页>>代码示例>>Java>>正文


Java DateTimeException.getMessage方法代码示例

本文整理汇总了Java中java.time.DateTimeException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeException.getMessage方法的具体用法?Java DateTimeException.getMessage怎么用?Java DateTimeException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.DateTimeException的用法示例。


在下文中一共展示了DateTimeException.getMessage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_throws_message

import java.time.DateTimeException; //导入方法依赖的package包/类
@Test(dataProvider="nozone_exception_cases")
public void test_throws_message(Temporal temporal, String pattern, String queryName) {
    DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern);
    try {
        fmt.format(temporal);
        fail("Format using \"" + pattern + "\" with " +
                temporal + " should have failed");
    } catch (DateTimeException dte) {
        String msg = dte.getMessage();
        // Verify message contains the type that is missing and the temporal value
        assertTrue(msg.contains(queryName),
                String.format("\"%s\" missing from %s", queryName, msg));
        String s = temporal.toString();
        assertTrue(msg.contains(s),
                String.format("\"%s\" missing from %s", s, msg));
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TestDateTimeFormatter.java

示例2: test_throws_message_chrono

import java.time.DateTimeException; //导入方法依赖的package包/类
@Test
public void test_throws_message_chrono() {
    Chronology chrono = ThaiBuddhistChronology.INSTANCE;
    DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendZoneId().toFormatter()
            .withChronology(chrono);
    LocalTime now = LocalTime.now();
    try {
        fmt.format(now);
        fail("Format using appendZoneId() should have failed");
    } catch (DateTimeException dte) {
        String msg = dte.getMessage();
        // Verify message contains the type that is missing and the temporal value
        assertTrue(msg.contains("ZoneId"),
                String.format("\"%s\" missing from %s", "ZoneId", msg));
        assertTrue(msg.contains(chrono.toString()),
                String.format("\"%s\" missing from %s", chrono.toString(), msg));
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TestDateTimeFormatter.java

示例3: test_throws_message_zone

import java.time.DateTimeException; //导入方法依赖的package包/类
@Test
public void test_throws_message_zone() {
    ZoneId zone = ZoneId.of("Pacific/Honolulu");
    DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendChronologyId().toFormatter()
            .withZone(zone);
    LocalTime now = LocalTime.now();
    try {
        fmt.format(now);
        fail("Format using appendChronologyId() should have failed");
    } catch (DateTimeException dte) {
        String msg = dte.getMessage();
        // Verify message contains the type that is missing and the temporal value
        assertTrue(msg.contains("Chronology"),
                String.format("\"%s\" missing from %s", "Chronology", msg));
        assertTrue(msg.contains(zone.toString()),
                String.format("\"%s\" missing from %s", zone.toString(), msg));
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TestDateTimeFormatter.java

示例4: assertGoodErrorDate

import java.time.DateTimeException; //导入方法依赖的package包/类
private void assertGoodErrorDate(Function<TemporalAccessor, Object> function, String expectedText) {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-mm-dd");
    TemporalAccessor temporal = f.parse("2010-06-30");
    try {
        function.apply(temporal);
        fail("Should have failed");
    } catch (DateTimeException ex) {
        String msg = ex.getMessage();
        assertTrue(msg.contains(expectedText), msg);
        assertTrue(msg.contains("Year"), msg);
        assertTrue(msg.contains("MinuteOfHour"), msg);
        assertTrue(msg.contains("DayOfMonth"), msg);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:TestDateTimeFormatter.java

示例5: assertGoodErrorTime

import java.time.DateTimeException; //导入方法依赖的package包/类
private void assertGoodErrorTime(Function<TemporalAccessor, Object> function, String expectedText) {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("HH:MM:ss");
    TemporalAccessor temporal = f.parse("11:30:56");
    try {
        function.apply(temporal);
        fail("Should have failed");
    } catch (DateTimeException ex) {
        String msg = ex.getMessage();
        assertTrue(msg.contains(expectedText), msg);
        assertTrue(msg.contains("HourOfDay"), msg);
        assertTrue(msg.contains("MonthOfYear"), msg);
        assertTrue(msg.contains("SecondOfMinute"), msg);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:TestDateTimeFormatter.java


注:本文中的java.time.DateTimeException.getMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。