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


Java XMLGregorianCalendar.setTime方法代码示例

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


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

示例1: testSetTime

import javax.xml.datatype.XMLGregorianCalendar; //导入方法依赖的package包/类
@Test
public final void testSetTime() {

    /**
     * Hour, minute, second values to test and expected result.
     */
    final int[] TEST_VALUES = { 24, 0, 0, TEST_VALUE_PASS, 24, 1, 0, TEST_VALUE_FAIL, 24, 0, 1, TEST_VALUE_FAIL, 24, DatatypeConstants.FIELD_UNDEFINED, 0,
            TEST_VALUE_FAIL, 24, 0, DatatypeConstants.FIELD_UNDEFINED, TEST_VALUE_FAIL };

    // create DatatypeFactory
    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException datatypeConfigurationException) {
        Assert.fail(datatypeConfigurationException.toString());
    }

    if (DEBUG) {
        System.err.println("DatatypeFactory created: " + datatypeFactory.toString());
    }

    // create XMLGregorianCalendar
    XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar();

    // test each value
    for (int onTestValue = 0; onTestValue < TEST_VALUES.length; onTestValue = onTestValue + 4) {

        if (DEBUG) {
            System.err.println("testing values: (" + TEST_VALUES[onTestValue] + ", " + TEST_VALUES[onTestValue + 1] + ", " + TEST_VALUES[onTestValue + 2]
                    + ") expected (0=fail, 1=pass): " + TEST_VALUES[onTestValue + 3]);
        }

        try {
            // set time
            xmlGregorianCalendar.setTime(TEST_VALUES[onTestValue], TEST_VALUES[onTestValue + 1], TEST_VALUES[onTestValue + 2]);

            if (DEBUG) {
                System.err.println("XMLGregorianCalendar created: \"" + xmlGregorianCalendar.toString() + "\"");
            }

            // was this expected to fail?
            if (TEST_VALUES[onTestValue + 3] == TEST_VALUE_FAIL) {
                Assert.fail("the values: (" + TEST_VALUES[onTestValue] + ", " + TEST_VALUES[onTestValue + 1] + ", " + TEST_VALUES[onTestValue + 2]
                        + ") are invalid, " + "yet it created the XMLGregorianCalendar \"" + xmlGregorianCalendar.toString() + "\"");
            }
        } catch (Exception exception) {

            if (DEBUG) {
                System.err.println("Exception in creating XMLGregorianCalendar: \"" + exception.toString() + "\"");
            }

            // was this expected to succed?
            if (TEST_VALUES[onTestValue + 3] == TEST_VALUE_PASS) {
                Assert.fail("the values: (" + TEST_VALUES[onTestValue] + ", " + TEST_VALUES[onTestValue + 1] + ", " + TEST_VALUES[onTestValue + 2]
                        + ") are valid yet it failed with \"" + exception.toString() + "\"");
            }
            // expected failure
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:XMLGregorianCalendarTest.java

示例2: testSetHour

import javax.xml.datatype.XMLGregorianCalendar; //导入方法依赖的package包/类
@Test
public final void testSetHour() {

    /**
     * Hour values to test and expected result.
     */
    final int[] TEST_VALUES = {
            // setTime(H, M, S), hour override, expected result
            0, 0, 0, 0, TEST_VALUE_PASS, 0, 0, 0, 23, TEST_VALUE_PASS, 0, 0, 0, 24, TEST_VALUE_PASS,
            // creates invalid state
            0, 0, 0, DatatypeConstants.FIELD_UNDEFINED, TEST_VALUE_FAIL,
            // violates Schema Errata
            0, 0, 1, 24, TEST_VALUE_FAIL };

    // create DatatypeFactory
    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException datatypeConfigurationException) {
        Assert.fail(datatypeConfigurationException.toString());
    }

    if (DEBUG) {
        System.err.println("DatatypeFactory created: " + datatypeFactory.toString());
    }

    // create XMLGregorianCalendar
    XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar();

    // test each value
    for (int onTestValue = 0; onTestValue < TEST_VALUES.length; onTestValue = onTestValue + 5) {

        if (DEBUG) {
            System.err.println("testing values: (" + TEST_VALUES[onTestValue] + ", " + TEST_VALUES[onTestValue + 1] + ", " + TEST_VALUES[onTestValue + 2]
                    + ", " + TEST_VALUES[onTestValue + 3] + ") expected (0=fail, 1=pass): " + TEST_VALUES[onTestValue + 4]);
        }

        try {
            // set time to known valid value
            xmlGregorianCalendar.setTime(TEST_VALUES[onTestValue], TEST_VALUES[onTestValue + 1], TEST_VALUES[onTestValue + 2]);
            // now explicitly set hour
            xmlGregorianCalendar.setHour(TEST_VALUES[onTestValue + 3]);

            if (DEBUG) {
                System.err.println("XMLGregorianCalendar created: \"" + xmlGregorianCalendar.toString() + "\"");
            }

            // was this expected to fail?
            if (TEST_VALUES[onTestValue + 4] == TEST_VALUE_FAIL) {
                Assert.fail("the values: (" + TEST_VALUES[onTestValue] + ", " + TEST_VALUES[onTestValue + 1] + ", " + TEST_VALUES[onTestValue + 2] + ", "
                        + TEST_VALUES[onTestValue + 3] + ") are invalid, " + "yet it created the XMLGregorianCalendar \"" + xmlGregorianCalendar.toString()
                        + "\"");
            }
        } catch (Exception exception) {

            if (DEBUG) {
                System.err.println("Exception in creating XMLGregorianCalendar: \"" + exception.toString() + "\"");
            }

            // was this expected to succed?
            if (TEST_VALUES[onTestValue + 4] == TEST_VALUE_PASS) {
                Assert.fail("the values: (" + TEST_VALUES[onTestValue] + ", " + TEST_VALUES[onTestValue + 1] + ", " + TEST_VALUES[onTestValue + 2] + ", "
                        + TEST_VALUES[onTestValue + 3] + ") are valid yet it failed with \"" + exception.toString() + "\"");
            }
            // expected failure
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:69,代码来源:XMLGregorianCalendarTest.java


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