diff --git a/xstream/src/test/com/thoughtworks/acceptance/Time18TypesTest.java b/xstream/src/test/com/thoughtworks/acceptance/Time18TypesTest.java index ebc1a1477..e51ca9452 100644 --- a/xstream/src/test/com/thoughtworks/acceptance/Time18TypesTest.java +++ b/xstream/src/test/com/thoughtworks/acceptance/Time18TypesTest.java @@ -33,6 +33,39 @@ */ public class Time18TypesTest extends AbstractAcceptanceTest { + public void testDuration() { + assertBothWays(Duration.ofDays(1000), "PT24000H"); + assertBothWays(Duration.ofHours(50), "PT50H"); + assertBothWays(Duration.ofMinutes(77), "PT1H17M"); + assertBothWays(Duration.ofSeconds(55), "PT55S"); + assertBothWays(Duration.ofMillis(4444), "PT4.444S"); + assertBothWays(Duration.ofNanos(123456789), "PT0.123456789S"); + assertBothWays(Duration.ofNanos(100000000), "PT0.1S"); + assertBothWays(Duration.ofNanos(9), "PT0.000000009S"); + assertBothWays(Duration.ofNanos(6333123456789L), "PT1H45M33.123456789S"); + assertBothWays(Duration.ofSeconds(-3), "PT-3S"); + assertBothWays(Duration.ofSeconds(-30001), "PT-8H-20M-1S"); + } + + public void testDurationWithOldFormat() { + assertEquals(Duration.ofSeconds(7777), xstream.fromXML("" // + + "\n" // + + " 1\n" // + + " 7777\n" // + + " 0\n" // + + "")); + } + + public void testDurationIsImmutable() { + final Duration[] array = new Duration[2]; + array[0] = array[1] = Duration.ofHours(50); + assertBothWays(array, "" // + + "\n" // + + " PT50H\n" // + + " PT50H\n" // + + ""); + } + public void testInstant() { assertBothWays(Instant.from(ZonedDateTime.of(2017, 7, 30, 20, 40, 0, 0, ZoneOffset.of("Z"))), "2017-07-30T20:40:00Z"); @@ -54,11 +87,11 @@ public void testInstant() { public void testInstantWithOldFormat() { assertEquals(Instant.parse("2017-02-15T18:49:25Z"), xstream.fromXML("" // - + "\n" // + + "\n" // + " 2\n" // + " 1487184565\n" // + " 0\n" // - + "")); + + "")); } public void testInstantIsImmutable() { @@ -71,89 +104,6 @@ public void testInstantIsImmutable() { + ""); } - public void testZoneOffest() { - assertBothWays(ZoneOffset.of("Z"), "Z"); - assertBothWays(ZoneOffset.ofTotalSeconds(7777), "+02:09:37"); - assertBothWays(ZoneId.ofOffset("GMT", ZoneOffset.ofTotalSeconds(7777)), "GMT+02:09:37"); - assertBothWays(ZoneId.of("ECT", ZoneId.SHORT_IDS), "Europe/Paris"); - assertBothWays(ZoneId.of("CET"), "CET"); - } - - public void testZoneOffestWithOldFormat() { - assertEquals(ZoneOffset.ofTotalSeconds(7777), xstream.fromXML("" // - + "\n" // - + " 8\n" // - + " 127\n" // - + " 7777\n" // - + "")); - } - - public void testZoneOffestIsImmutable() { - final ZoneOffset[] array = new ZoneOffset[2]; - array[0] = array[1] = ZoneOffset.of("Z"); - assertBothWays(array, "" // - + "\n" // - + " Z\n" // - + " Z\n" // - + ""); - } - - public void testZoneRegion() { - assertBothWays(ZoneId.of("America/Caracas"), "America/Caracas"); - assertBothWays(ZoneId.of("Europe/Berlin"), "Europe/Berlin"); - } - - public void testZoneRegionWithOldFormat() { - assertEquals(ZoneId.of("America/Caracas"), xstream.fromXML("" // - + "\n" // - + " 7\n" // - + " America/Caracas\n" // - + "")); - } - - public void testZoneRegionIsImmutable() { - final ZoneId[] array = new ZoneId[2]; - array[0] = array[1] = ZoneId.of("Europe/Rome"); - assertBothWays(array, "" // - + "\n" // - + " Europe/Rome\n" // - + " Europe/Rome\n" // - + ""); - } - - public void testDuration() { - assertBothWays(Duration.ofDays(1000), "PT24000H"); - assertBothWays(Duration.ofHours(50), "PT50H"); - assertBothWays(Duration.ofMinutes(77), "PT1H17M"); - assertBothWays(Duration.ofSeconds(55), "PT55S"); - assertBothWays(Duration.ofMillis(4444), "PT4.444S"); - assertBothWays(Duration.ofNanos(123456789), "PT0.123456789S"); - assertBothWays(Duration.ofNanos(100000000), "PT0.1S"); - assertBothWays(Duration.ofNanos(9), "PT0.000000009S"); - assertBothWays(Duration.ofNanos(6333123456789L), "PT1H45M33.123456789S"); - assertBothWays(Duration.ofSeconds(-3), "PT-3S"); - assertBothWays(Duration.ofSeconds(-30001), "PT-8H-20M-1S"); - } - - public void testDurationWithOldFormat() { - assertEquals(Duration.ofSeconds(7777), xstream.fromXML("" // - + "\n" // - + " 1\n" // - + " 7777\n" // - + " 0\n" // - + "")); - } - - public void testDurationIsImmutable() { - final Duration[] array = new Duration[2]; - array[0] = array[1] = Duration.ofHours(50); - assertBothWays(array, "" // - + "\n" // - + " PT50H\n" // - + " PT50H\n" // - + ""); - } - public void testPeriod() { assertBothWays(Period.ofDays(1000), "P1000D"); assertBothWays(Period.ofWeeks(70), "P490D"); @@ -272,6 +222,30 @@ public void testLocalTimeIsImmutable() { + ""); } + public void testMonthDay() { + assertBothWays(MonthDay.of(1, 13), "--01-13"); + assertBothWays(MonthDay.of(2, 29), "--02-29"); + } + + public void testMonthDayWithOldFormat() { + assertEquals(MonthDay.of(Month.JANUARY, 13), xstream.fromXML("" // + + "\n" // + + " 13\n" // + + " 1\n" // + + " 13\n" // + + "")); + } + + public void testMonthDayIsImmutable() { + final MonthDay array[] = new MonthDay[2]; + array[0] = array[1] = MonthDay.of(Month.APRIL, 10); + assertBothWays(array, "" // + + "\n" + + " --04-10\n" // + + " --04-10\n" // + + ""); + } + public void testOffsetDateTime() { assertBothWays(OffsetDateTime.of(2017, 7, 30, 20, 40, 0, 0, ZoneOffset.ofHours(0)), "2017-07-30T20:40:00Z"); @@ -359,30 +333,6 @@ public void testOffsetTimeIsImmutable() { + ""); } - public void testMonthDay() { - assertBothWays(MonthDay.of(1, 13), "--01-13"); - assertBothWays(MonthDay.of(2, 29), "--02-29"); - } - - public void testMonthDayWithOldFormat() { - assertEquals(MonthDay.of(Month.JANUARY, 13), xstream.fromXML("" // - + "\n" // - + " 13\n" // - + " 1\n" // - + " 13\n" // - + "")); - } - - public void testMonthDayIsImmutable() { - final MonthDay array[] = new MonthDay[2]; - array[0] = array[1] = MonthDay.of(Month.APRIL, 10); - assertBothWays(array, "" // - + "\n" - + " --04-10\n" // - + " --04-10\n" // - + ""); - } - public void testYear() { assertBothWays(Year.of(2017), "2017"); assertBothWays(Year.of(0), "0"); @@ -475,4 +425,54 @@ public void testZonedDateTimeIsImmutable() { + " 2017-10-30T20:40:15+01:00[Europe/Paris]\n" + ""); } + + public void testZoneOffest() { + assertBothWays(ZoneOffset.of("Z"), "Z"); + assertBothWays(ZoneOffset.ofTotalSeconds(7777), "+02:09:37"); + assertBothWays(ZoneId.ofOffset("GMT", ZoneOffset.ofTotalSeconds(7777)), "GMT+02:09:37"); + assertBothWays(ZoneId.of("ECT", ZoneId.SHORT_IDS), "Europe/Paris"); + assertBothWays(ZoneId.of("CET"), "CET"); + } + + public void testZoneOffestWithOldFormat() { + assertEquals(ZoneOffset.ofTotalSeconds(7777), xstream.fromXML("" // + + "\n" // + + " 8\n" // + + " 127\n" // + + " 7777\n" // + + "")); + } + + public void testZoneOffestIsImmutable() { + final ZoneOffset[] array = new ZoneOffset[2]; + array[0] = array[1] = ZoneOffset.of("Z"); + assertBothWays(array, "" // + + "\n" // + + " Z\n" // + + " Z\n" // + + ""); + } + + public void testZoneRegion() { + assertBothWays(ZoneId.of("America/Caracas"), "America/Caracas"); + assertBothWays(ZoneId.of("Europe/Berlin"), "Europe/Berlin"); + } + + public void testZoneRegionWithOldFormat() { + assertEquals(ZoneId.of("America/Caracas"), xstream.fromXML("" // + + "\n" // + + " 7\n" // + + " America/Caracas\n" // + + "")); + } + + public void testZoneRegionIsImmutable() { + final ZoneId[] array = new ZoneId[2]; + array[0] = array[1] = ZoneId.of("Europe/Rome"); + assertBothWays(array, "" // + + "\n" // + + " Europe/Rome\n" // + + " Europe/Rome\n" // + + ""); + } }