From 0f3ca0317ac464939c8cdcb12a7f2bf4024e84a3 Mon Sep 17 00:00:00 2001 From: rriggs Date: Thu, 22 Aug 2013 10:01:47 -0700 Subject: [PATCH] 8024896: Refactor java.time serialization tests into separate subpackage Summary: Move serialization tests to .serial subpackage Reviewed-by: sherman Contributed-by: paul.rank@oracle.com --- test/java/time/tck/java/time/TCKDuration.java | 20 -- test/java/time/tck/java/time/TCKInstant.java | 18 -- .../java/time/tck/java/time/TCKLocalDate.java | 22 -- .../time/tck/java/time/TCKLocalDateTime.java | 25 -- .../java/time/tck/java/time/TCKLocalTime.java | 57 ---- test/java/time/tck/java/time/TCKMonthDay.java | 18 -- .../time/tck/java/time/TCKOffsetDateTime.java | 37 --- .../time/tck/java/time/TCKOffsetTime.java | 34 --- test/java/time/tck/java/time/TCKPeriod.java | 8 - test/java/time/tck/java/time/TCKYear.java | 19 -- .../java/time/tck/java/time/TCKYearMonth.java | 18 -- test/java/time/tck/java/time/TCKZoneId.java | 104 ------- .../time/tck/java/time/TCKZoneOffset.java | 40 --- .../time/tck/java/time/TCKZonedDateTime.java | 48 ---- .../java/time/chrono/TCKChronoLocalDate.java | 17 -- .../time/chrono/TCKChronoLocalDateTime.java | 17 -- .../chrono/serial/TCKChronoLocalDate.java | 111 ++++++++ .../chrono/serial/TCKChronoLocalDateTime.java | 110 ++++++++ .../TCKChronologySerialization.java | 8 +- .../tck/java/time/serial/TCKDuration.java | 95 +++++++ .../time/tck/java/time/serial/TCKInstant.java | 95 +++++++ .../tck/java/time/serial/TCKLocalDate.java | 107 +++++++ .../java/time/serial/TCKLocalDateTime.java | 104 +++++++ .../tck/java/time/serial/TCKLocalTime.java | 145 ++++++++++ .../tck/java/time/serial/TCKMonthDay.java | 107 +++++++ .../java/time/serial/TCKOffsetDateTime.java | 127 +++++++++ .../tck/java/time/serial/TCKOffsetTime.java | 122 ++++++++ .../time/tck/java/time/serial/TCKPeriod.java | 82 ++++++ .../time/tck/java/time/serial/TCKYear.java | 94 +++++++ .../tck/java/time/serial/TCKYearMonth.java | 106 +++++++ .../time/tck/java/time/serial/TCKZoneId.java | 263 ++++++++++++++++++ .../tck/java/time/serial/TCKZoneOffset.java | 118 ++++++++ .../java/time/serial/TCKZonedDateTime.java | 143 ++++++++++ .../tck/java/time/temporal/TCKWeekFields.java | 6 - .../time/temporal/serial/TCKWeekFields.java | 94 +++++++ .../tck/java/time/zone/TCKFixedZoneRules.java | 18 -- .../time/zone/TCKZoneOffsetTransition.java | 14 - .../zone/TCKZoneOffsetTransitionRule.java | 25 -- .../time/tck/java/time/zone/TCKZoneRules.java | 21 -- .../time/zone/serial/TCKFixedZoneRules.java | 117 ++++++++ .../zone/serial/TCKZoneOffsetTransition.java | 91 ++++++ .../serial/TCKZoneOffsetTransitionRule.java | 114 ++++++++ .../java/time/zone/serial/TCKZoneRules.java | 122 ++++++++ 43 files changed, 2471 insertions(+), 590 deletions(-) create mode 100644 test/java/time/tck/java/time/chrono/serial/TCKChronoLocalDate.java create mode 100644 test/java/time/tck/java/time/chrono/serial/TCKChronoLocalDateTime.java rename test/java/time/tck/java/time/chrono/{ => serial}/TCKChronologySerialization.java (96%) create mode 100644 test/java/time/tck/java/time/serial/TCKDuration.java create mode 100644 test/java/time/tck/java/time/serial/TCKInstant.java create mode 100644 test/java/time/tck/java/time/serial/TCKLocalDate.java create mode 100644 test/java/time/tck/java/time/serial/TCKLocalDateTime.java create mode 100644 test/java/time/tck/java/time/serial/TCKLocalTime.java create mode 100644 test/java/time/tck/java/time/serial/TCKMonthDay.java create mode 100644 test/java/time/tck/java/time/serial/TCKOffsetDateTime.java create mode 100644 test/java/time/tck/java/time/serial/TCKOffsetTime.java create mode 100644 test/java/time/tck/java/time/serial/TCKPeriod.java create mode 100644 test/java/time/tck/java/time/serial/TCKYear.java create mode 100644 test/java/time/tck/java/time/serial/TCKYearMonth.java create mode 100644 test/java/time/tck/java/time/serial/TCKZoneId.java create mode 100644 test/java/time/tck/java/time/serial/TCKZoneOffset.java create mode 100644 test/java/time/tck/java/time/serial/TCKZonedDateTime.java create mode 100644 test/java/time/tck/java/time/temporal/serial/TCKWeekFields.java create mode 100644 test/java/time/tck/java/time/zone/serial/TCKFixedZoneRules.java create mode 100644 test/java/time/tck/java/time/zone/serial/TCKZoneOffsetTransition.java create mode 100644 test/java/time/tck/java/time/zone/serial/TCKZoneOffsetTransitionRule.java create mode 100644 test/java/time/tck/java/time/zone/serial/TCKZoneRules.java diff --git a/test/java/time/tck/java/time/TCKDuration.java b/test/java/time/tck/java/time/TCKDuration.java index bae2cf698..c3bb0c9c9 100644 --- a/test/java/time/tck/java/time/TCKDuration.java +++ b/test/java/time/tck/java/time/TCKDuration.java @@ -103,26 +103,6 @@ public class TCKDuration extends AbstractTCKTest { private static final long CYCLE_SECS = 146097L * 86400L; - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(Duration.ofHours(5)); - assertSerializable(Duration.ofHours(0)); - assertSerializable(Duration.ofHours(-5)); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(1); - dos.writeLong(654321); - dos.writeInt(123456789); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(Duration.ofSeconds(654321, 123456789), bytes); - } - //----------------------------------------------------------------------- // constants //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/TCKInstant.java b/test/java/time/tck/java/time/TCKInstant.java index 05d7b83fc..bb3a765de 100644 --- a/test/java/time/tck/java/time/TCKInstant.java +++ b/test/java/time/tck/java/time/TCKInstant.java @@ -154,24 +154,6 @@ public class TCKInstant extends AbstractDateTimeTest { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(Instant.ofEpochMilli(134l)); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(2); - dos.writeLong(654321); - dos.writeInt(123456789); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(Instant.ofEpochSecond(654321, 123456789), bytes); - } - //----------------------------------------------------------------------- private void check(Instant instant, long epochSecs, int nos) { assertEquals(instant.getEpochSecond(), epochSecs); diff --git a/test/java/time/tck/java/time/TCKLocalDate.java b/test/java/time/tck/java/time/TCKLocalDate.java index 597dd4f65..3d4cbbbc8 100644 --- a/test/java/time/tck/java/time/TCKLocalDate.java +++ b/test/java/time/tck/java/time/TCKLocalDate.java @@ -196,28 +196,6 @@ public class TCKLocalDate extends AbstractDateTimeTest { return list; } - - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(TEST_2007_07_15); - assertSerializable(LocalDate.MIN); - assertSerializable(LocalDate.MAX); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(3); - dos.writeInt(2012); - dos.writeByte(9); - dos.writeByte(16); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(LocalDate.of(2012, 9, 16), bytes); - } - //----------------------------------------------------------------------- private void check(LocalDate test, int y, int m, int d) { assertEquals(test.getYear(), y); diff --git a/test/java/time/tck/java/time/TCKLocalDateTime.java b/test/java/time/tck/java/time/TCKLocalDateTime.java index f55bdb4a9..040704cd9 100644 --- a/test/java/time/tck/java/time/TCKLocalDateTime.java +++ b/test/java/time/tck/java/time/TCKLocalDateTime.java @@ -241,31 +241,6 @@ public class TCKLocalDateTime extends AbstractDateTimeTest { return LocalDateTime.of(year, month, day, 0, 0); } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(TEST_2007_07_15_12_30_40_987654321); - assertSerializable(LocalDateTime.MIN); - assertSerializable(LocalDateTime.MAX); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(5); - dos.writeInt(2012); - dos.writeByte(9); - dos.writeByte(16); - dos.writeByte(22); - dos.writeByte(17); - dos.writeByte(59); - dos.writeInt(459_000_000); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(LocalDateTime.of(2012, 9, 16, 22, 17, 59, 459_000_000), bytes); - } - //----------------------------------------------------------------------- // constants //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/TCKLocalTime.java b/test/java/time/tck/java/time/TCKLocalTime.java index dbba80d1c..2291b5ca1 100644 --- a/test/java/time/tck/java/time/TCKLocalTime.java +++ b/test/java/time/tck/java/time/TCKLocalTime.java @@ -191,64 +191,7 @@ public class TCKLocalTime extends AbstractDateTimeTest { } //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(TEST_12_30_40_987654321); - assertSerializable(LocalTime.MIN); - assertSerializable(LocalTime.MAX); - } - - @Test - public void test_serialization_format_h() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(4); - dos.writeByte(-1 - 22); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(LocalTime.of(22, 0), bytes); - } - - @Test - public void test_serialization_format_hm() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(4); - dos.writeByte(22); - dos.writeByte(-1 - 17); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(LocalTime.of(22, 17), bytes); - } - @Test - public void test_serialization_format_hms() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(4); - dos.writeByte(22); - dos.writeByte(17); - dos.writeByte(-1 - 59); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(LocalTime.of(22, 17, 59), bytes); - } - - @Test - public void test_serialization_format_hmsn() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(4); - dos.writeByte(22); - dos.writeByte(17); - dos.writeByte(59); - dos.writeInt(459_000_000); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(LocalTime.of(22, 17, 59, 459_000_000), bytes); - } - - //----------------------------------------------------------------------- private void check(LocalTime test, int h, int m, int s, int n) { assertEquals(test.getHour(), h); assertEquals(test.getMinute(), m); diff --git a/test/java/time/tck/java/time/TCKMonthDay.java b/test/java/time/tck/java/time/TCKMonthDay.java index f2a2b93f4..e9b1730cb 100644 --- a/test/java/time/tck/java/time/TCKMonthDay.java +++ b/test/java/time/tck/java/time/TCKMonthDay.java @@ -136,24 +136,6 @@ public class TCKMonthDay extends AbstractDateTimeTest { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws ClassNotFoundException, IOException { - assertSerializable(TEST_07_15); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(13); // java.time.temporal.Ser.MONTH_DAY_TYPE - dos.writeByte(9); - dos.writeByte(16); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(MonthDay.of(9, 16), bytes); - } - //----------------------------------------------------------------------- void check(MonthDay test, int m, int d) { assertEquals(test.getMonth().getValue(), m); diff --git a/test/java/time/tck/java/time/TCKOffsetDateTime.java b/test/java/time/tck/java/time/TCKOffsetDateTime.java index 7cfc2a61d..0cf024fdd 100644 --- a/test/java/time/tck/java/time/TCKOffsetDateTime.java +++ b/test/java/time/tck/java/time/TCKOffsetDateTime.java @@ -209,43 +209,6 @@ public class TCKOffsetDateTime extends AbstractDateTimeTest { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(TEST_2008_6_30_11_30_59_000000500); - assertSerializable(OffsetDateTime.MIN); - assertSerializable(OffsetDateTime.MAX); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(10); // java.time.Ser.OFFSET_DATE_TIME_TYPE - } - byte[] bytes = baos.toByteArray(); - ByteArrayOutputStream baosDateTime = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baosDateTime) ) { - dos.writeByte(5); - dos.writeInt(2012); - dos.writeByte(9); - dos.writeByte(16); - dos.writeByte(22); - dos.writeByte(17); - dos.writeByte(59); - dos.writeInt(464_000_000); - } - byte[] bytesDateTime = baosDateTime.toByteArray(); - ByteArrayOutputStream baosOffset = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baosOffset) ) { - dos.writeByte(8); - dos.writeByte(4); // quarter hours stored: 3600 / 900 - } - byte[] bytesOffset = baosOffset.toByteArray(); - LocalDateTime ldt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 464_000_000); - assertSerializedBySer(OffsetDateTime.of(ldt, ZoneOffset.ofHours(1)), bytes, bytesDateTime, bytesOffset); - } - //----------------------------------------------------------------------- // constants //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/TCKOffsetTime.java b/test/java/time/tck/java/time/TCKOffsetTime.java index b3d7e5b26..ee5b2d3f6 100644 --- a/test/java/time/tck/java/time/TCKOffsetTime.java +++ b/test/java/time/tck/java/time/TCKOffsetTime.java @@ -183,40 +183,6 @@ public class TCKOffsetTime extends AbstractDateTimeTest { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(TEST_11_30_59_500_PONE); - assertSerializable(OffsetTime.MIN); - assertSerializable(OffsetTime.MAX); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(9); // java.time.Ser.OFFSET_TIME_TYPE - } - byte[] bytes = baos.toByteArray(); - ByteArrayOutputStream baosTime = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baosTime) ) { - dos.writeByte(4); - dos.writeByte(22); - dos.writeByte(17); - dos.writeByte(59); - dos.writeInt(464_000_000); - } - byte[] bytesTime = baosTime.toByteArray(); - ByteArrayOutputStream baosOffset = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baosOffset) ) { - dos.writeByte(8); - dos.writeByte(4); // quarter hours stored: 3600 / 900 - } - byte[] bytesOffset = baosOffset.toByteArray(); - assertSerializedBySer(OffsetTime.of(22, 17, 59, 464_000_000, ZoneOffset.ofHours(1)), bytes, - bytesTime, bytesOffset); - } - //----------------------------------------------------------------------- // constants //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/TCKPeriod.java b/test/java/time/tck/java/time/TCKPeriod.java index 7a06b95e6..3a1fe42ec 100644 --- a/test/java/time/tck/java/time/TCKPeriod.java +++ b/test/java/time/tck/java/time/TCKPeriod.java @@ -86,14 +86,6 @@ import org.testng.annotations.Test; @Test public class TCKPeriod extends AbstractTCKTest { - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(Period.ZERO); - assertSerializable(Period.ofDays(1)); - assertSerializable(Period.of(1, 2, 3)); - } - //----------------------------------------------------------------------- // ofYears(int) //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/TCKYear.java b/test/java/time/tck/java/time/TCKYear.java index 53f0db0b5..c0a35967a 100644 --- a/test/java/time/tck/java/time/TCKYear.java +++ b/test/java/time/tck/java/time/TCKYear.java @@ -151,25 +151,6 @@ public class TCKYear extends AbstractDateTimeTest { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(Year.of(2)); - assertSerializable(Year.of(0)); - assertSerializable(Year.of(-2)); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(11); // java.time.temporal.Ser.YEAR_TYPE - dos.writeInt(2012); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(Year.of(2012), bytes); - } - //----------------------------------------------------------------------- // now() //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/TCKYearMonth.java b/test/java/time/tck/java/time/TCKYearMonth.java index 66f691b07..e1f1a4665 100644 --- a/test/java/time/tck/java/time/TCKYearMonth.java +++ b/test/java/time/tck/java/time/TCKYearMonth.java @@ -156,24 +156,6 @@ public class TCKYearMonth extends AbstractDateTimeTest { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws IOException, ClassNotFoundException { - assertSerializable(TEST_2008_06); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(12); // java.time.temporal.Ser.YEAR_MONTH_TYPE - dos.writeInt(2012); - dos.writeByte(9); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(YearMonth.of(2012, 9), bytes); - } - //----------------------------------------------------------------------- void check(YearMonth test, int y, int m) { assertEquals(test.getYear(), y); diff --git a/test/java/time/tck/java/time/TCKZoneId.java b/test/java/time/tck/java/time/TCKZoneId.java index c63b393d2..0d47403db 100644 --- a/test/java/time/tck/java/time/TCKZoneId.java +++ b/test/java/time/tck/java/time/TCKZoneId.java @@ -92,110 +92,6 @@ import org.testng.annotations.Test; @Test public class TCKZoneId extends AbstractTCKTest { - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(ZoneId.of("Europe/London")); - assertSerializable(ZoneId.of("America/Chicago")); - } - - @Test - public void test_serialization_format() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(7); - dos.writeUTF("Europe/London"); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(ZoneId.of("Europe/London"), bytes); - } - - @Test - public void test_deserialization_lenient_characters() throws Exception { - // an ID can be loaded without validation during deserialization - String id = "QWERTYUIOPASDFGHJKLZXCVBNM~/._+-"; - ZoneId deser = deserialize(id); - // getId, equals, hashCode, toString and normalized are OK - assertEquals(deser.getId(), id); - assertEquals(deser.toString(), id); - assertEquals(deser, deser); - assertEquals(deser.hashCode(), deser.hashCode()); - assertEquals(deser.normalized(), deser); - // getting the rules is not - try { - deser.getRules(); - fail(); - } catch (ZoneRulesException ex) { - // expected - } - } - - @Test(expectedExceptions=DateTimeException.class) - public void test_deserialization_lenient_badCharacters() throws Exception { - // an ID can be loaded without validation during deserialization - // but there is a check to ensure the ID format is valid - deserialize("|!?"); - } - - @Test(dataProvider="offsetBasedValid") - public void test_deserialization_lenient_offsetNotAllowed_noPrefix(String input, String resolvedId) throws Exception { - ZoneId deserialized = deserialize(input); - assertEquals(deserialized, ZoneId.of(input)); - assertEquals(deserialized, ZoneId.of(resolvedId)); - } - - @Test(dataProvider="offsetBasedValidPrefix") - public void test_deserialization_lenient_offsetNotAllowed_prefixUTC(String input, String resolvedId, String offsetId) throws Exception { - ZoneId deserialized = deserialize("UTC" + input); - assertEquals(deserialized, ZoneId.of("UTC" + input)); - assertEquals(deserialized, ZoneId.of("UTC" + resolvedId)); - } - - @Test(dataProvider="offsetBasedValidPrefix") - public void test_deserialization_lenient_offsetNotAllowed_prefixGMT(String input, String resolvedId, String offsetId) throws Exception { - ZoneId deserialized = deserialize("GMT" + input); - assertEquals(deserialized, ZoneId.of("GMT" + input)); - assertEquals(deserialized, ZoneId.of("GMT" + resolvedId)); - } - - @Test(dataProvider="offsetBasedValidPrefix") - public void test_deserialization_lenient_offsetNotAllowed_prefixUT(String input, String resolvedId, String offsetId) throws Exception { - ZoneId deserialized = deserialize("UT" + input); - assertEquals(deserialized, ZoneId.of("UT" + input)); - assertEquals(deserialized, ZoneId.of("UT" + resolvedId)); - } - - private ZoneId deserialize(String id) throws Exception { - String serClass = ZoneId.class.getPackage().getName() + ".Ser"; - Class serCls = Class.forName(serClass); - Field field = serCls.getDeclaredField("serialVersionUID"); - field.setAccessible(true); - long serVer = (Long) field.get(null); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos)) { - dos.writeShort(ObjectStreamConstants.STREAM_MAGIC); - dos.writeShort(ObjectStreamConstants.STREAM_VERSION); - dos.writeByte(ObjectStreamConstants.TC_OBJECT); - dos.writeByte(ObjectStreamConstants.TC_CLASSDESC); - dos.writeUTF(serClass); - dos.writeLong(serVer); - dos.writeByte(ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA); - dos.writeShort(0); // number of fields - dos.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); // end of classdesc - dos.writeByte(ObjectStreamConstants.TC_NULL); // no superclasses - dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA); - dos.writeByte(1 + 2 + id.length()); // length of data (1 byte + 2 bytes UTF length + 32 bytes UTF) - dos.writeByte(7); // ZoneId - dos.writeUTF(id); - dos.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); // end of blockdata - } - ZoneId deser = null; - try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - deser = (ZoneId) ois.readObject(); - } - return deser; - } - //----------------------------------------------------------------------- // OLD_SHORT_IDS //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/TCKZoneOffset.java b/test/java/time/tck/java/time/TCKZoneOffset.java index 94f2eb52e..cf9098a18 100644 --- a/test/java/time/tck/java/time/TCKZoneOffset.java +++ b/test/java/time/tck/java/time/TCKZoneOffset.java @@ -120,46 +120,6 @@ public class TCKZoneOffset extends AbstractDateTimeTest { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws Exception { - assertSerializable(ZoneOffset.of("+01:30")); - } - - @Test - public void test_serialization_format_quarterPositive() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(8); - dos.writeByte(6); // stored as quarter hours - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(ZoneOffset.ofHoursMinutes(1, 30), bytes); - } - - @Test - public void test_serialization_format_quarterNegative() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(8); - dos.writeByte(-10); // stored as quarter hours - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(ZoneOffset.ofHoursMinutes(-2, -30), bytes); - } - - @Test - public void test_serialization_format_full() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(8); - dos.writeByte(127); - dos.writeInt(53265); - } - byte[] bytes = baos.toByteArray(); - assertSerializedBySer(ZoneOffset.ofTotalSeconds(53265), bytes); - } - //----------------------------------------------------------------------- // constants //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/TCKZonedDateTime.java b/test/java/time/tck/java/time/TCKZonedDateTime.java index d1db67fca..1f5bee322 100644 --- a/test/java/time/tck/java/time/TCKZonedDateTime.java +++ b/test/java/time/tck/java/time/TCKZonedDateTime.java @@ -222,54 +222,6 @@ public class TCKZonedDateTime extends AbstractDateTimeTest { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws ClassNotFoundException, IOException { - assertSerializable(TEST_DATE_TIME); - } - - @Test - public void test_serialization_format_zoneId() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(6); - dos.writeInt(2012); // date - dos.writeByte(9); - dos.writeByte(16); - dos.writeByte(22); // time - dos.writeByte(17); - dos.writeByte(59); - dos.writeInt(470_000_000); - dos.writeByte(4); // offset - dos.writeByte(7); // zoneId - dos.writeUTF("Europe/London"); - } - byte[] bytes = baos.toByteArray(); - ZonedDateTime zdt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 470_000_000).atZone(ZoneId.of("Europe/London")); - assertSerializedBySer(zdt, bytes); - } - - @Test - public void test_serialization_format_zoneOffset() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (DataOutputStream dos = new DataOutputStream(baos) ) { - dos.writeByte(6); - dos.writeInt(2012); // date - dos.writeByte(9); - dos.writeByte(16); - dos.writeByte(22); // time - dos.writeByte(17); - dos.writeByte(59); - dos.writeInt(470_000_000); - dos.writeByte(4); // offset - dos.writeByte(8); // zoneId - dos.writeByte(4); - } - byte[] bytes = baos.toByteArray(); - ZonedDateTime zdt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 470_000_000).atZone(ZoneOffset.ofHours(1)); - assertSerializedBySer(zdt, bytes); - } - //----------------------------------------------------------------------- // now() //----------------------------------------------------------------------- diff --git a/test/java/time/tck/java/time/chrono/TCKChronoLocalDate.java b/test/java/time/tck/java/time/chrono/TCKChronoLocalDate.java index 92f083ef6..32001354f 100644 --- a/test/java/time/tck/java/time/chrono/TCKChronoLocalDate.java +++ b/test/java/time/tck/java/time/chrono/TCKChronoLocalDate.java @@ -306,23 +306,6 @@ public class TCKChronoLocalDate { } } - //----------------------------------------------------------------------- - // Test Serialization of Calendars - //----------------------------------------------------------------------- - @Test( dataProvider="calendars") - public void test_ChronoSerialization(Chronology chrono) throws Exception { - LocalDate ref = LocalDate.of(2013, 1, 5); - ChronoLocalDate orginal = chrono.date(ref); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - @SuppressWarnings("unchecked") - ChronoLocalDate ser = (ChronoLocalDate) in.readObject(); - assertEquals(ser, orginal, "deserialized date is wrong"); - } //----------------------------------------------------------------------- @Test(dataProvider="calendars") diff --git a/test/java/time/tck/java/time/chrono/TCKChronoLocalDateTime.java b/test/java/time/tck/java/time/chrono/TCKChronoLocalDateTime.java index 129a19039..7ca03e2e3 100644 --- a/test/java/time/tck/java/time/chrono/TCKChronoLocalDateTime.java +++ b/test/java/time/tck/java/time/chrono/TCKChronoLocalDateTime.java @@ -317,23 +317,6 @@ public class TCKChronoLocalDateTime { } } - //----------------------------------------------------------------------- - // Test Serialization of ISO via chrono API - //----------------------------------------------------------------------- - @Test( dataProvider="calendars") - public void test_ChronoLocalDateTimeSerialization(Chronology chrono) throws Exception { - LocalDateTime ref = LocalDate.of(2013, 1, 5).atTime(12, 1, 2, 3); - ChronoLocalDateTime orginal = chrono.date(ref).atTime(ref.toLocalTime()); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - ChronoLocalDateTime ser = (ChronoLocalDateTime) in.readObject(); - assertEquals(ser, orginal, "deserialized date is wrong"); - } - //----------------------------------------------------------------------- @Test(dataProvider="calendars") public void test_from_TemporalAccessor(Chronology chrono) { diff --git a/test/java/time/tck/java/time/chrono/serial/TCKChronoLocalDate.java b/test/java/time/tck/java/time/chrono/serial/TCKChronoLocalDate.java new file mode 100644 index 000000000..4bec5cdc9 --- /dev/null +++ b/test/java/time/tck/java/time/chrono/serial/TCKChronoLocalDate.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.chrono.serial; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.time.LocalDate; +import java.time.chrono.*; + +import static org.testng.Assert.assertEquals; + +/** + * Test assertions that must be true for all built-in chronologies. + */ +@Test +public class TCKChronoLocalDate { + + //----------------------------------------------------------------------- + // regular data factory for names and descriptions of available calendars + //----------------------------------------------------------------------- + @DataProvider(name = "calendars") + Chronology[][] data_of_calendars() { + return new Chronology[][]{ + {HijrahChronology.INSTANCE}, + {IsoChronology.INSTANCE}, + {JapaneseChronology.INSTANCE}, + {MinguoChronology.INSTANCE}, + {ThaiBuddhistChronology.INSTANCE}}; + } + + + //----------------------------------------------------------------------- + // Test Serialization of Calendars + //----------------------------------------------------------------------- + @Test( dataProvider="calendars") + public void test_ChronoSerialization(Chronology chrono) throws Exception { + LocalDate ref = LocalDate.of(2013, 1, 5); + ChronoLocalDate orginal = chrono.date(ref); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(baos); + out.writeObject(orginal); + out.close(); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bais); + @SuppressWarnings("unchecked") + ChronoLocalDate ser = (ChronoLocalDate) in.readObject(); + assertEquals(ser, orginal, "deserialized date is wrong"); + } + + //----------------------------------------------------------------------- + +} diff --git a/test/java/time/tck/java/time/chrono/serial/TCKChronoLocalDateTime.java b/test/java/time/tck/java/time/chrono/serial/TCKChronoLocalDateTime.java new file mode 100644 index 000000000..1ab1cda92 --- /dev/null +++ b/test/java/time/tck/java/time/chrono/serial/TCKChronoLocalDateTime.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.chrono.serial; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.chrono.*; + +import static org.testng.Assert.assertEquals; + +/** + * Test assertions that must be true for all built-in chronologies. + */ +@Test +public class TCKChronoLocalDateTime { + + //----------------------------------------------------------------------- + // regular data factory for available calendars + //----------------------------------------------------------------------- + @DataProvider(name = "calendars") + Chronology[][] data_of_calendars() { + return new Chronology[][]{ + {HijrahChronology.INSTANCE}, + {IsoChronology.INSTANCE}, + {JapaneseChronology.INSTANCE}, + {MinguoChronology.INSTANCE}, + {ThaiBuddhistChronology.INSTANCE}}; + } + + //----------------------------------------------------------------------- + // Test Serialization ZonedDateTime for each Chronology + //----------------------------------------------------------------------- + @Test( dataProvider="calendars") + public void test_ChronoLocalDateTimeSerialization(Chronology chrono) throws Exception { + LocalDateTime ref = LocalDate.of(2013, 1, 5).atTime(12, 1, 2, 3); + ChronoLocalDateTime orginal = chrono.date(ref).atTime(ref.toLocalTime()); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(baos); + out.writeObject(orginal); + out.close(); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bais); + ChronoLocalDateTime ser = (ChronoLocalDateTime) in.readObject(); + assertEquals(ser, orginal, "deserialized date is wrong"); + } + + //----------------------------------------------------------------------- + +} diff --git a/test/java/time/tck/java/time/chrono/TCKChronologySerialization.java b/test/java/time/tck/java/time/chrono/serial/TCKChronologySerialization.java similarity index 96% rename from test/java/time/tck/java/time/chrono/TCKChronologySerialization.java rename to test/java/time/tck/java/time/chrono/serial/TCKChronologySerialization.java index 35620ad75..aed919ada 100644 --- a/test/java/time/tck/java/time/chrono/TCKChronologySerialization.java +++ b/test/java/time/tck/java/time/chrono/serial/TCKChronologySerialization.java @@ -54,7 +54,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package tck.java.time.chrono; +package tck.java.time.chrono.serial; import static org.testng.Assert.assertEquals; @@ -73,6 +73,7 @@ import java.time.chrono.ThaiBuddhistChronology; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +@Test public class TCKChronologySerialization { //----------------------------------------------------------------------- @@ -93,13 +94,12 @@ public class TCKChronologySerialization { //----------------------------------------------------------------------- @Test(dataProvider="calendars") public void test_ChronoSerialization(Chronology chrono) throws Exception { + System.out.printf(" ChronoSerialization: %s%n", chrono); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(chrono); out.close(); - - byte[] bytes = baos.toByteArray(); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); @SuppressWarnings("unchecked") diff --git a/test/java/time/tck/java/time/serial/TCKDuration.java b/test/java/time/tck/java/time/serial/TCKDuration.java new file mode 100644 index 000000000..e4a9a3f9a --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKDuration.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2007-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.Duration; + +/** + * Test Duration. + */ +@Test +public class TCKDuration extends AbstractTCKTest { + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(Duration.ofHours(5)); + assertSerializable(Duration.ofHours(0)); + assertSerializable(Duration.ofHours(-5)); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(1); + dos.writeLong(654321); + dos.writeInt(123456789); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(Duration.ofSeconds(654321, 123456789), bytes); + } + +} diff --git a/test/java/time/tck/java/time/serial/TCKInstant.java b/test/java/time/tck/java/time/serial/TCKInstant.java new file mode 100644 index 000000000..783ad5863 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKInstant.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2007-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.Instant; + +/** + * Test Instant. + */ +@Test +public class TCKInstant extends AbstractTCKTest { + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(Instant.ofEpochMilli(134l)); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(2); + dos.writeLong(654321); + dos.writeInt(123456789); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(Instant.ofEpochSecond(654321, 123456789), bytes); + } + + +} diff --git a/test/java/time/tck/java/time/serial/TCKLocalDate.java b/test/java/time/tck/java/time/serial/TCKLocalDate.java new file mode 100644 index 000000000..aeaa96d37 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKLocalDate.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2007-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.LocalDate; + +/** + * Test LocalDate. + */ +@Test +public class TCKLocalDate extends AbstractTCKTest { + + private LocalDate TEST_2007_07_15; + + @BeforeMethod + public void setUp() { + TEST_2007_07_15 = LocalDate.of(2007, 7, 15); + } + + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(TEST_2007_07_15); + assertSerializable(LocalDate.MIN); + assertSerializable(LocalDate.MAX); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(3); + dos.writeInt(2012); + dos.writeByte(9); + dos.writeByte(16); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(LocalDate.of(2012, 9, 16), bytes); + } + + //----------------------------------------------------------------------- + +} diff --git a/test/java/time/tck/java/time/serial/TCKLocalDateTime.java b/test/java/time/tck/java/time/serial/TCKLocalDateTime.java new file mode 100644 index 000000000..a2ae9d235 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKLocalDateTime.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.LocalDateTime; + +/** + * Test LocalDateTime. + */ +@Test +public class TCKLocalDateTime extends AbstractTCKTest { + + private LocalDateTime TEST_2007_07_15_12_30_40_987654321 = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321); + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(TEST_2007_07_15_12_30_40_987654321); + assertSerializable(LocalDateTime.MIN); + assertSerializable(LocalDateTime.MAX); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(5); + dos.writeInt(2012); + dos.writeByte(9); + dos.writeByte(16); + dos.writeByte(22); + dos.writeByte(17); + dos.writeByte(59); + dos.writeInt(459_000_000); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(LocalDateTime.of(2012, 9, 16, 22, 17, 59, 459_000_000), bytes); + } + + + +} diff --git a/test/java/time/tck/java/time/serial/TCKLocalTime.java b/test/java/time/tck/java/time/serial/TCKLocalTime.java new file mode 100644 index 000000000..06f2ce4c8 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKLocalTime.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2007-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.LocalTime; + +/** + * Test LocalTime. + */ +@Test +public class TCKLocalTime extends AbstractTCKTest { + + + private LocalTime TEST_12_30_40_987654321; + + + @BeforeMethod + public void setUp() { + TEST_12_30_40_987654321 = LocalTime.of(12, 30, 40, 987654321); + } + + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(TEST_12_30_40_987654321); + assertSerializable(LocalTime.MIN); + assertSerializable(LocalTime.MAX); + } + + @Test + public void test_serialization_format_h() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(4); + dos.writeByte(-1 - 22); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(LocalTime.of(22, 0), bytes); + } + + @Test + public void test_serialization_format_hm() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(4); + dos.writeByte(22); + dos.writeByte(-1 - 17); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(LocalTime.of(22, 17), bytes); + } + + @Test + public void test_serialization_format_hms() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(4); + dos.writeByte(22); + dos.writeByte(17); + dos.writeByte(-1 - 59); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(LocalTime.of(22, 17, 59), bytes); + } + + @Test + public void test_serialization_format_hmsn() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(4); + dos.writeByte(22); + dos.writeByte(17); + dos.writeByte(59); + dos.writeInt(459_000_000); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(LocalTime.of(22, 17, 59, 459_000_000), bytes); + } + + +} diff --git a/test/java/time/tck/java/time/serial/TCKMonthDay.java b/test/java/time/tck/java/time/serial/TCKMonthDay.java new file mode 100644 index 000000000..cd4416630 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKMonthDay.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.time.MonthDay; + +/** + * Test MonthDay. + */ +@Test +public class TCKMonthDay extends AbstractTCKTest { + + private MonthDay TEST_07_15; + + @BeforeMethod + public void setUp() { + TEST_07_15 = MonthDay.of(7, 15); + } + + + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws ClassNotFoundException, IOException { + assertSerializable(TEST_07_15); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(13); // java.time.temporal.Ser.MONTH_DAY_TYPE + dos.writeByte(9); + dos.writeByte(16); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(MonthDay.of(9, 16), bytes); + } + + //----------------------------------------------------------------------- + + +} diff --git a/test/java/time/tck/java/time/serial/TCKOffsetDateTime.java b/test/java/time/tck/java/time/serial/TCKOffsetDateTime.java new file mode 100644 index 000000000..8a1406b87 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKOffsetDateTime.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; + +/** + * Test OffsetDateTime. + */ +@Test +public class TCKOffsetDateTime extends AbstractTCKTest { + + private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1); + private OffsetDateTime TEST_2008_6_30_11_30_59_000000500; + + @BeforeMethod + public void setUp() { + TEST_2008_6_30_11_30_59_000000500 = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 500, OFFSET_PONE); + } + + //----------------------------------------------------------------------- + + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(TEST_2008_6_30_11_30_59_000000500); + assertSerializable(OffsetDateTime.MIN); + assertSerializable(OffsetDateTime.MAX); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(10); // java.time.Ser.OFFSET_DATE_TIME_TYPE + } + byte[] bytes = baos.toByteArray(); + ByteArrayOutputStream baosDateTime = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baosDateTime) ) { + dos.writeByte(5); + dos.writeInt(2012); + dos.writeByte(9); + dos.writeByte(16); + dos.writeByte(22); + dos.writeByte(17); + dos.writeByte(59); + dos.writeInt(464_000_000); + } + byte[] bytesDateTime = baosDateTime.toByteArray(); + ByteArrayOutputStream baosOffset = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baosOffset) ) { + dos.writeByte(8); + dos.writeByte(4); // quarter hours stored: 3600 / 900 + } + byte[] bytesOffset = baosOffset.toByteArray(); + LocalDateTime ldt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 464_000_000); + assertSerializedBySer(OffsetDateTime.of(ldt, ZoneOffset.ofHours(1)), bytes, bytesDateTime, bytesOffset); + } + + +} diff --git a/test/java/time/tck/java/time/serial/TCKOffsetTime.java b/test/java/time/tck/java/time/serial/TCKOffsetTime.java new file mode 100644 index 000000000..6bdddba2f --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKOffsetTime.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.OffsetTime; +import java.time.ZoneOffset; + +/** + * Test OffsetTime. + */ +@Test +public class TCKOffsetTime extends AbstractTCKTest { + + private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1); + private OffsetTime TEST_11_30_59_500_PONE; + + @BeforeMethod + public void setUp() { + TEST_11_30_59_500_PONE = OffsetTime.of(11, 30, 59, 500, OFFSET_PONE); + } + + + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(TEST_11_30_59_500_PONE); + assertSerializable(OffsetTime.MIN); + assertSerializable(OffsetTime.MAX); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(9); // java.time.Ser.OFFSET_TIME_TYPE + } + byte[] bytes = baos.toByteArray(); + ByteArrayOutputStream baosTime = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baosTime) ) { + dos.writeByte(4); + dos.writeByte(22); + dos.writeByte(17); + dos.writeByte(59); + dos.writeInt(464_000_000); + } + byte[] bytesTime = baosTime.toByteArray(); + ByteArrayOutputStream baosOffset = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baosOffset) ) { + dos.writeByte(8); + dos.writeByte(4); // quarter hours stored: 3600 / 900 + } + byte[] bytesOffset = baosOffset.toByteArray(); + assertSerializedBySer(OffsetTime.of(22, 17, 59, 464_000_000, ZoneOffset.ofHours(1)), bytes, + bytesTime, bytesOffset); + } + + +} diff --git a/test/java/time/tck/java/time/serial/TCKPeriod.java b/test/java/time/tck/java/time/serial/TCKPeriod.java new file mode 100644 index 000000000..2f94df132 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKPeriod.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.time.Period; + +/** + * Test Period. + */ +@Test +public class TCKPeriod extends AbstractTCKTest { + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(Period.ZERO); + assertSerializable(Period.ofDays(1)); + assertSerializable(Period.of(1, 2, 3)); + } + + +} diff --git a/test/java/time/tck/java/time/serial/TCKYear.java b/test/java/time/tck/java/time/serial/TCKYear.java new file mode 100644 index 000000000..954dacf0c --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKYear.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.Year; + +/** + * Test Year. + */ +@Test +public class TCKYear extends AbstractTCKTest { + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(Year.of(2)); + assertSerializable(Year.of(0)); + assertSerializable(Year.of(-2)); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(11); // java.time.temporal.Ser.YEAR_TYPE + dos.writeInt(2012); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(Year.of(2012), bytes); + } + +} diff --git a/test/java/time/tck/java/time/serial/TCKYearMonth.java b/test/java/time/tck/java/time/serial/TCKYearMonth.java new file mode 100644 index 000000000..675767d97 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKYearMonth.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.time.YearMonth; + +/** + * Test YearMonth. + */ +@Test +public class TCKYearMonth extends AbstractTCKTest { + + private YearMonth TEST_2008_06; + + @BeforeMethod + public void setUp() { + TEST_2008_06 = YearMonth.of(2008, 6); + } + + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws IOException, ClassNotFoundException { + assertSerializable(TEST_2008_06); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(12); // java.time.temporal.Ser.YEAR_MONTH_TYPE + dos.writeInt(2012); + dos.writeByte(9); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(YearMonth.of(2012, 9), bytes); + } + + //----------------------------------------------------------------------- + + +} diff --git a/test/java/time/tck/java/time/serial/TCKZoneId.java b/test/java/time/tck/java/time/serial/TCKZoneId.java new file mode 100644 index 000000000..26923f12a --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKZoneId.java @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.*; +import java.lang.reflect.Field; +import java.time.DateTimeException; +import java.time.ZoneId; +import java.time.zone.ZoneRulesException; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +/** + * Test ZoneId. + */ +@Test +public class TCKZoneId extends AbstractTCKTest { + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(ZoneId.of("Europe/London")); + assertSerializable(ZoneId.of("America/Chicago")); + } + + @Test + public void test_serialization_format() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(7); + dos.writeUTF("Europe/London"); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(ZoneId.of("Europe/London"), bytes); + } + + @Test + public void test_deserialization_lenient_characters() throws Exception { + // an ID can be loaded without validation during deserialization + String id = "QWERTYUIOPASDFGHJKLZXCVBNM~/._+-"; + ZoneId deser = deserialize(id); + // getId, equals, hashCode, toString and normalized are OK + assertEquals(deser.getId(), id); + assertEquals(deser.toString(), id); + assertEquals(deser, deser); + assertEquals(deser.hashCode(), deser.hashCode()); + assertEquals(deser.normalized(), deser); + // getting the rules is not + try { + deser.getRules(); + fail(); + } catch (ZoneRulesException ex) { + // expected + } + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_deserialization_lenient_badCharacters() throws Exception { + // an ID can be loaded without validation during deserialization + // but there is a check to ensure the ID format is valid + deserialize("|!?"); + } + + @Test(dataProvider="offsetBasedValid") + public void test_deserialization_lenient_offsetNotAllowed_noPrefix(String input, String resolvedId) throws Exception { + ZoneId deserialized = deserialize(input); + assertEquals(deserialized, ZoneId.of(input)); + assertEquals(deserialized, ZoneId.of(resolvedId)); + } + + @Test(dataProvider="offsetBasedValidPrefix") + public void test_deserialization_lenient_offsetNotAllowed_prefixUTC(String input, String resolvedId, String offsetId) throws Exception { + ZoneId deserialized = deserialize("UTC" + input); + assertEquals(deserialized, ZoneId.of("UTC" + input)); + assertEquals(deserialized, ZoneId.of("UTC" + resolvedId)); + } + + @Test(dataProvider="offsetBasedValidPrefix") + public void test_deserialization_lenient_offsetNotAllowed_prefixGMT(String input, String resolvedId, String offsetId) throws Exception { + ZoneId deserialized = deserialize("GMT" + input); + assertEquals(deserialized, ZoneId.of("GMT" + input)); + assertEquals(deserialized, ZoneId.of("GMT" + resolvedId)); + } + + @Test(dataProvider="offsetBasedValidPrefix") + public void test_deserialization_lenient_offsetNotAllowed_prefixUT(String input, String resolvedId, String offsetId) throws Exception { + ZoneId deserialized = deserialize("UT" + input); + assertEquals(deserialized, ZoneId.of("UT" + input)); + assertEquals(deserialized, ZoneId.of("UT" + resolvedId)); + } + + private ZoneId deserialize(String id) throws Exception { + String serClass = ZoneId.class.getPackage().getName() + ".Ser"; + Class serCls = Class.forName(serClass); + Field field = serCls.getDeclaredField("serialVersionUID"); + field.setAccessible(true); + long serVer = (Long) field.get(null); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos)) { + dos.writeShort(ObjectStreamConstants.STREAM_MAGIC); + dos.writeShort(ObjectStreamConstants.STREAM_VERSION); + dos.writeByte(ObjectStreamConstants.TC_OBJECT); + dos.writeByte(ObjectStreamConstants.TC_CLASSDESC); + dos.writeUTF(serClass); + dos.writeLong(serVer); + dos.writeByte(ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA); + dos.writeShort(0); // number of fields + dos.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); // end of classdesc + dos.writeByte(ObjectStreamConstants.TC_NULL); // no superclasses + dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA); + dos.writeByte(1 + 2 + id.length()); // length of data (1 byte + 2 bytes UTF length + 32 bytes UTF) + dos.writeByte(7); // ZoneId + dos.writeUTF(id); + dos.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); // end of blockdata + } + ZoneId deser = null; + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + deser = (ZoneId) ois.readObject(); + } + return deser; + } + + //----------------------------------------------------------------------- + // regular factory and .normalized() + //----------------------------------------------------------------------- + @DataProvider(name="offsetBasedValid") + Object[][] data_offsetBasedValid() { + return new Object[][] { + {"Z", "Z"}, + {"+0", "Z"}, + {"-0", "Z"}, + {"+00", "Z"}, + {"+0000", "Z"}, + {"+00:00", "Z"}, + {"+000000", "Z"}, + {"+00:00:00", "Z"}, + {"-00", "Z"}, + {"-0000", "Z"}, + {"-00:00", "Z"}, + {"-000000", "Z"}, + {"-00:00:00", "Z"}, + {"+5", "+05:00"}, + {"+01", "+01:00"}, + {"+0100", "+01:00"}, + {"+01:00", "+01:00"}, + {"+010000", "+01:00"}, + {"+01:00:00", "+01:00"}, + {"+12", "+12:00"}, + {"+1234", "+12:34"}, + {"+12:34", "+12:34"}, + {"+123456", "+12:34:56"}, + {"+12:34:56", "+12:34:56"}, + {"-02", "-02:00"}, + {"-5", "-05:00"}, + {"-0200", "-02:00"}, + {"-02:00", "-02:00"}, + {"-020000", "-02:00"}, + {"-02:00:00", "-02:00"}, + }; + } + + //----------------------------------------------------------------------- + @DataProvider(name="offsetBasedValidPrefix") + Object[][] data_offsetBasedValidPrefix() { + return new Object[][] { + {"", "", "Z"}, + {"+0", "", "Z"}, + {"-0", "", "Z"}, + {"+00", "", "Z"}, + {"+0000", "", "Z"}, + {"+00:00", "", "Z"}, + {"+000000", "", "Z"}, + {"+00:00:00", "", "Z"}, + {"-00", "", "Z"}, + {"-0000", "", "Z"}, + {"-00:00", "", "Z"}, + {"-000000", "", "Z"}, + {"-00:00:00", "", "Z"}, + {"+5", "+05:00", "+05:00"}, + {"+01", "+01:00", "+01:00"}, + {"+0100", "+01:00", "+01:00"}, + {"+01:00", "+01:00", "+01:00"}, + {"+010000", "+01:00", "+01:00"}, + {"+01:00:00", "+01:00", "+01:00"}, + {"+12", "+12:00", "+12:00"}, + {"+1234", "+12:34", "+12:34"}, + {"+12:34", "+12:34", "+12:34"}, + {"+123456", "+12:34:56", "+12:34:56"}, + {"+12:34:56", "+12:34:56", "+12:34:56"}, + {"-02", "-02:00", "-02:00"}, + {"-5", "-05:00", "-05:00"}, + {"-0200", "-02:00", "-02:00"}, + {"-02:00", "-02:00", "-02:00"}, + {"-020000", "-02:00", "-02:00"}, + {"-02:00:00", "-02:00", "-02:00"}, + }; + } + + + +} diff --git a/test/java/time/tck/java/time/serial/TCKZoneOffset.java b/test/java/time/tck/java/time/serial/TCKZoneOffset.java new file mode 100644 index 000000000..61196e909 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKZoneOffset.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.time.ZoneOffset; + +/** + * Test ZoneOffset. + */ +@Test +public class TCKZoneOffset extends AbstractTCKTest { + + + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws Exception { + assertSerializable(ZoneOffset.of("+01:30")); + } + + @Test + public void test_serialization_format_quarterPositive() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(8); + dos.writeByte(6); // stored as quarter hours + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(ZoneOffset.ofHoursMinutes(1, 30), bytes); + } + + @Test + public void test_serialization_format_quarterNegative() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(8); + dos.writeByte(-10); // stored as quarter hours + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(ZoneOffset.ofHoursMinutes(-2, -30), bytes); + } + + @Test + public void test_serialization_format_full() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(8); + dos.writeByte(127); + dos.writeInt(53265); + } + byte[] bytes = baos.toByteArray(); + assertSerializedBySer(ZoneOffset.ofTotalSeconds(53265), bytes); + } + + +} diff --git a/test/java/time/tck/java/time/serial/TCKZonedDateTime.java b/test/java/time/tck/java/time/serial/TCKZonedDateTime.java new file mode 100644 index 000000000..a44946b74 --- /dev/null +++ b/test/java/time/tck/java/time/serial/TCKZonedDateTime.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.serial; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; + +/** + * Test ZonedDateTime. + */ +@Test +public class TCKZonedDateTime extends AbstractTCKTest { + + private static final ZoneOffset OFFSET_0100 = ZoneOffset.ofHours(1); + private static final ZoneId ZONE_0100 = OFFSET_0100; + private static final ZoneId ZONE_PARIS = ZoneId.of("Europe/Paris"); + private LocalDateTime TEST_LOCAL_2008_06_30_11_30_59_500; + private ZonedDateTime TEST_DATE_TIME; + + + @BeforeMethod + public void setUp() { + TEST_LOCAL_2008_06_30_11_30_59_500 = LocalDateTime.of(2008, 6, 30, 11, 30, 59, 500); + TEST_DATE_TIME = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); + } + + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws ClassNotFoundException, IOException { + assertSerializable(TEST_DATE_TIME); + } + + @Test + public void test_serialization_format_zoneId() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(6); + dos.writeInt(2012); // date + dos.writeByte(9); + dos.writeByte(16); + dos.writeByte(22); // time + dos.writeByte(17); + dos.writeByte(59); + dos.writeInt(470_000_000); + dos.writeByte(4); // offset + dos.writeByte(7); // zoneId + dos.writeUTF("Europe/London"); + } + byte[] bytes = baos.toByteArray(); + ZonedDateTime zdt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 470_000_000).atZone(ZoneId.of("Europe/London")); + assertSerializedBySer(zdt, bytes); + } + + @Test + public void test_serialization_format_zoneOffset() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DataOutputStream dos = new DataOutputStream(baos) ) { + dos.writeByte(6); + dos.writeInt(2012); // date + dos.writeByte(9); + dos.writeByte(16); + dos.writeByte(22); // time + dos.writeByte(17); + dos.writeByte(59); + dos.writeInt(470_000_000); + dos.writeByte(4); // offset + dos.writeByte(8); // zoneId + dos.writeByte(4); + } + byte[] bytes = baos.toByteArray(); + ZonedDateTime zdt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 470_000_000).atZone(ZoneOffset.ofHours(1)); + assertSerializedBySer(zdt, bytes); + } + + +} diff --git a/test/java/time/tck/java/time/temporal/TCKWeekFields.java b/test/java/time/tck/java/time/temporal/TCKWeekFields.java index 4367ee925..f2e948843 100644 --- a/test/java/time/tck/java/time/temporal/TCKWeekFields.java +++ b/test/java/time/tck/java/time/temporal/TCKWeekFields.java @@ -713,12 +713,6 @@ public class TCKWeekFields extends AbstractTCKTest { } } - //----------------------------------------------------------------------- - @Test(dataProvider="weekFields") - public void test_serializable_singleton(DayOfWeek firstDayOfWeek, int minDays) throws IOException, ClassNotFoundException { - WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays); - assertSerializableSame(weekDef); // spec state singleton - } //----------------------------------------------------------------------- @DataProvider(name="weekFields") diff --git a/test/java/time/tck/java/time/temporal/serial/TCKWeekFields.java b/test/java/time/tck/java/time/temporal/serial/TCKWeekFields.java new file mode 100644 index 000000000..749515e7c --- /dev/null +++ b/test/java/time/tck/java/time/temporal/serial/TCKWeekFields.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.temporal.serial; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.io.IOException; +import java.time.DayOfWeek; +import java.time.temporal.WeekFields; + +/** + * Test WeekFields. + */ +@Test +public class TCKWeekFields extends AbstractTCKTest { + + //----------------------------------------------------------------------- + @Test(dataProvider="weekFields") + public void test_serializable_singleton(DayOfWeek firstDayOfWeek, int minDays) throws IOException, ClassNotFoundException { + WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays); + assertSerializableSame(weekDef); // spec state singleton + } + + //----------------------------------------------------------------------- + @DataProvider(name="weekFields") + Object[][] data_weekFields() { + Object[][] objects = new Object[49][]; + int i = 0; + for (DayOfWeek firstDayOfWeek : DayOfWeek.values()) { + for (int minDays = 1; minDays <= 7; minDays++) { + objects[i++] = new Object[] {firstDayOfWeek, minDays}; + } + } + return objects; + } + + +} diff --git a/test/java/time/tck/java/time/zone/TCKFixedZoneRules.java b/test/java/time/tck/java/time/zone/TCKFixedZoneRules.java index 418d1ad9e..08df54333 100644 --- a/test/java/time/tck/java/time/zone/TCKFixedZoneRules.java +++ b/test/java/time/tck/java/time/zone/TCKFixedZoneRules.java @@ -107,25 +107,7 @@ public class TCKFixedZoneRules { //----------------------------------------------------------------------- // Basics //----------------------------------------------------------------------- - @Test(dataProvider="rules") - public void test_serialization(ZoneRules test, ZoneOffset expectedOffset) throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(test); - baos.close(); - byte[] bytes = baos.toByteArray(); - - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - ObjectInputStream in = new ObjectInputStream(bais); - ZoneRules result = (ZoneRules) in.readObject(); - - assertEquals(result, test); - assertEquals(result.getClass(), test.getClass()); - } - //----------------------------------------------------------------------- - // basics - //----------------------------------------------------------------------- @Test(dataProvider="rules") public void test_getOffset_Instant(ZoneRules test, ZoneOffset expectedOffset) { assertEquals(test.getOffset(INSTANT), expectedOffset); diff --git a/test/java/time/tck/java/time/zone/TCKZoneOffsetTransition.java b/test/java/time/tck/java/time/zone/TCKZoneOffsetTransition.java index c5da309d8..891deb767 100644 --- a/test/java/time/tck/java/time/zone/TCKZoneOffsetTransition.java +++ b/test/java/time/tck/java/time/zone/TCKZoneOffsetTransition.java @@ -146,20 +146,6 @@ public class TCKZoneOffsetTransition extends AbstractTCKTest { assertSerializable(test); } - //----------------------------------------------------------------------- - @Test - public void test_serialization_unusual1() throws Exception { - LocalDateTime ldt = LocalDateTime.of(Year.MAX_VALUE, 12, 31, 1, 31, 53); - ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, ZoneOffset.of("+02:04:56"), ZoneOffset.of("-10:02:34")); - assertSerializable(test); - } - - @Test - public void test_serialization_unusual2() throws Exception { - LocalDateTime ldt = LocalDateTime.of(Year.MIN_VALUE, 1, 1, 12, 1, 3); - ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, ZoneOffset.of("+02:04:56"), ZoneOffset.of("+10:02:34")); - assertSerializable(test); - } //----------------------------------------------------------------------- // isValidOffset() diff --git a/test/java/time/tck/java/time/zone/TCKZoneOffsetTransitionRule.java b/test/java/time/tck/java/time/zone/TCKZoneOffsetTransitionRule.java index fedded753..9ad26627e 100644 --- a/test/java/time/tck/java/time/zone/TCKZoneOffsetTransitionRule.java +++ b/test/java/time/tck/java/time/zone/TCKZoneOffsetTransitionRule.java @@ -210,31 +210,6 @@ public class TCKZoneOffsetTransitionRule extends AbstractTCKTest { assertSerializable(test); } - @Test - public void test_serialization_unusualOffsets() throws Exception { - ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( - Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD, - ZoneOffset.ofHoursMinutesSeconds(-12, -20, -50), - ZoneOffset.ofHoursMinutesSeconds(-4, -10, -34), - ZoneOffset.ofHours(-18)); - assertSerializable(test); - } - - @Test - public void test_serialization_endOfDay() throws Exception { - ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( - Month.MARCH, 20, DayOfWeek.FRIDAY, LocalTime.MIDNIGHT, true, TimeDefinition.UTC, - OFFSET_0200, OFFSET_0200, OFFSET_0300); - assertSerializable(test); - } - - @Test - public void test_serialization_unusualTime() throws Exception { - ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( - Month.MARCH, 20, DayOfWeek.WEDNESDAY, LocalTime.of(13, 34, 56), false, TimeDefinition.STANDARD, - OFFSET_0200, OFFSET_0200, OFFSET_0300); - assertSerializable(test); - } //----------------------------------------------------------------------- // createTransition() diff --git a/test/java/time/tck/java/time/zone/TCKZoneRules.java b/test/java/time/tck/java/time/zone/TCKZoneRules.java index af07063eb..19f8239c2 100644 --- a/test/java/time/tck/java/time/zone/TCKZoneRules.java +++ b/test/java/time/tck/java/time/zone/TCKZoneRules.java @@ -103,28 +103,7 @@ public class TCKZoneRules { private static final int OVERLAP = 2; private static final int GAP = 0; - //----------------------------------------------------------------------- - // Basics - //----------------------------------------------------------------------- - public void test_serialization_loaded() throws Exception { - assertSerialization(europeLondon()); - assertSerialization(europeParis()); - assertSerialization(americaNewYork()); - } - private void assertSerialization(ZoneRules test) throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(test); - baos.close(); - byte[] bytes = baos.toByteArray(); - - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - ObjectInputStream in = new ObjectInputStream(bais); - ZoneRules result = (ZoneRules) in.readObject(); - - assertEquals(result, test); - } //----------------------------------------------------------------------- // Europe/London diff --git a/test/java/time/tck/java/time/zone/serial/TCKFixedZoneRules.java b/test/java/time/tck/java/time/zone/serial/TCKFixedZoneRules.java new file mode 100644 index 000000000..b5d88d4f9 --- /dev/null +++ b/test/java/time/tck/java/time/zone/serial/TCKFixedZoneRules.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2010-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.zone.serial; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.time.ZoneOffset; +import java.time.zone.ZoneRules; + +import static org.testng.Assert.assertEquals; + +/** + * Test ZoneRules for fixed offset time-zones. + */ +@Test +public class TCKFixedZoneRules { + + private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1); + private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2); + private static final ZoneOffset OFFSET_M18 = ZoneOffset.ofHours(-18); + + private ZoneRules make(ZoneOffset offset) { + return offset.getRules(); + } + + @DataProvider(name="rules") + Object[][] data_rules() { + return new Object[][] { + {make(OFFSET_PONE), OFFSET_PONE}, + {make(OFFSET_PTWO), OFFSET_PTWO}, + {make(OFFSET_M18), OFFSET_M18}, + }; + } + + //----------------------------------------------------------------------- + // Basics + //----------------------------------------------------------------------- + @Test(dataProvider="rules") + public void test_serialization(ZoneRules test, ZoneOffset expectedOffset) throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(baos); + out.writeObject(test); + baos.close(); + byte[] bytes = baos.toByteArray(); + + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream in = new ObjectInputStream(bais); + ZoneRules result = (ZoneRules) in.readObject(); + + assertEquals(result, test); + assertEquals(result.getClass(), test.getClass()); + } + + +} diff --git a/test/java/time/tck/java/time/zone/serial/TCKZoneOffsetTransition.java b/test/java/time/tck/java/time/zone/serial/TCKZoneOffsetTransition.java new file mode 100644 index 000000000..a57d31eaf --- /dev/null +++ b/test/java/time/tck/java/time/zone/serial/TCKZoneOffsetTransition.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2010-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.zone.serial; + +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +import java.time.LocalDateTime; +import java.time.Year; +import java.time.ZoneOffset; +import java.time.zone.ZoneOffsetTransition; + +/** + * Test ZoneOffsetTransition. + */ +@Test +public class TCKZoneOffsetTransition extends AbstractTCKTest { + + //----------------------------------------------------------------------- + @Test + public void test_serialization_unusual1() throws Exception { + LocalDateTime ldt = LocalDateTime.of(Year.MAX_VALUE, 12, 31, 1, 31, 53); + ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, ZoneOffset.of("+02:04:56"), ZoneOffset.of("-10:02:34")); + assertSerializable(test); + } + + @Test + public void test_serialization_unusual2() throws Exception { + LocalDateTime ldt = LocalDateTime.of(Year.MIN_VALUE, 1, 1, 12, 1, 3); + ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, ZoneOffset.of("+02:04:56"), ZoneOffset.of("+10:02:34")); + assertSerializable(test); + } + +} diff --git a/test/java/time/tck/java/time/zone/serial/TCKZoneOffsetTransitionRule.java b/test/java/time/tck/java/time/zone/serial/TCKZoneOffsetTransitionRule.java new file mode 100644 index 000000000..1ccae56c8 --- /dev/null +++ b/test/java/time/tck/java/time/zone/serial/TCKZoneOffsetTransitionRule.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2010-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.zone.serial; + +import static org.testng.Assert.assertEquals; + +import java.time.DayOfWeek; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Month; +import java.time.ZoneOffset; +import java.time.zone.ZoneOffsetTransitionRule; +import java.time.zone.ZoneOffsetTransitionRule.TimeDefinition; + +import org.testng.annotations.Test; +import tck.java.time.AbstractTCKTest; + +/** + * Test ZoneOffsetTransitionRule. + */ +@Test +public class TCKZoneOffsetTransitionRule extends AbstractTCKTest { + + private static final LocalTime TIME_0100 = LocalTime.of(1, 0); + private static final ZoneOffset OFFSET_0200 = ZoneOffset.ofHours(2); + private static final ZoneOffset OFFSET_0300 = ZoneOffset.ofHours(3); + + + + @Test + public void test_serialization_unusualOffsets() throws Exception { + ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( + Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD, + ZoneOffset.ofHoursMinutesSeconds(-12, -20, -50), + ZoneOffset.ofHoursMinutesSeconds(-4, -10, -34), + ZoneOffset.ofHours(-18)); + assertSerializable(test); + } + + @Test + public void test_serialization_endOfDay() throws Exception { + ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( + Month.MARCH, 20, DayOfWeek.FRIDAY, LocalTime.MIDNIGHT, true, TimeDefinition.UTC, + OFFSET_0200, OFFSET_0200, OFFSET_0300); + assertSerializable(test); + } + + @Test + public void test_serialization_unusualTime() throws Exception { + ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( + Month.MARCH, 20, DayOfWeek.WEDNESDAY, LocalTime.of(13, 34, 56), false, TimeDefinition.STANDARD, + OFFSET_0200, OFFSET_0200, OFFSET_0300); + assertSerializable(test); + } + + +} diff --git a/test/java/time/tck/java/time/zone/serial/TCKZoneRules.java b/test/java/time/tck/java/time/zone/serial/TCKZoneRules.java new file mode 100644 index 000000000..6f83223f0 --- /dev/null +++ b/test/java/time/tck/java/time/zone/serial/TCKZoneRules.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tck.java.time.zone.serial; + +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.time.ZoneId; +import java.time.zone.ZoneRules; + +import static org.testng.Assert.assertEquals; + +/** + * Test ZoneRules. + */ +@Test +public class TCKZoneRules { + + public void test_serialization_loaded() throws Exception { + assertSerialization(europeLondon()); + assertSerialization(europeParis()); + assertSerialization(americaNewYork()); + } + + private void assertSerialization(ZoneRules test) throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(baos); + out.writeObject(test); + baos.close(); + byte[] bytes = baos.toByteArray(); + + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream in = new ObjectInputStream(bais); + ZoneRules result = (ZoneRules) in.readObject(); + + assertEquals(result, test); + } + + //----------------------------------------------------------------------- + // Europe/London + //----------------------------------------------------------------------- + private ZoneRules europeLondon() { + return ZoneId.of("Europe/London").getRules(); + } + + + //----------------------------------------------------------------------- + // Europe/Paris + //----------------------------------------------------------------------- + private ZoneRules europeParis() { + return ZoneId.of("Europe/Paris").getRules(); + } + + //----------------------------------------------------------------------- + // America/New_York + //----------------------------------------------------------------------- + private ZoneRules americaNewYork() { + return ZoneId.of("America/New_York").getRules(); + } + + +} -- GitLab