當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。