Skip to content

Commit

Permalink
Fix immutability for ZoneOffset and ZoneRegion.
Browse files Browse the repository at this point in the history
  • Loading branch information
joehni committed Feb 13, 2017
1 parent 6030856 commit 994e569
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion xstream/src/java/com/thoughtworks/xstream/XStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,9 @@ protected void setupImmutableTypes() {
addImmutableTypeDynamically("java.time.Year", false);
addImmutableTypeDynamically("java.time.YearMonth", false);
addImmutableTypeDynamically("java.time.ZonedDateTime", false);
addImmutableTypeDynamically("java.time.ZonedId", false);
addImmutableTypeDynamically("java.time.ZoneId", false);
addImmutableTypeDynamically("java.time.ZoneOffset", false);
addImmutableTypeDynamically("java.time.ZoneRegion", false);
}
}

Expand Down
20 changes: 20 additions & 0 deletions xstream/src/test/com/thoughtworks/acceptance/Time18TypesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public void testZoneOffestWithOldFormat() {
+ "</java.time.ZoneOffset>"));
}

public void testZoneOffestIsImmutable() {
final ZoneOffset[] array = new ZoneOffset[2];
array[0] = array[1] = ZoneOffset.of("Z");
assertBothWays(array, "" //
+ "<zone-id-array>\n" //
+ " <zone-id>Z</zone-id>\n" //
+ " <zone-id>Z</zone-id>\n" //
+ "</zone-id-array>");
}

public void testZoneRegion() {
assertBothWays(ZoneId.of("America/Caracas"), "<zone-id>America/Caracas</zone-id>");
assertBothWays(ZoneId.of("Europe/Berlin"), "<zone-id>Europe/Berlin</zone-id>");
Expand All @@ -62,6 +72,16 @@ public void testZoneRegionWithOldFormat() {
+ "</java.time.ZoneRegion>"));
}

public void testZoneRegionIsImmutable() {
final ZoneId[] array = new ZoneId[2];
array[0] = array[1] = ZoneId.of("Europe/Rome");
assertBothWays(array, "" //
+ "<zone-id-array>\n" //
+ " <zone-id>Europe/Rome</zone-id>\n" //
+ " <zone-id>Europe/Rome</zone-id>\n" //
+ "</zone-id-array>");
}

public void testDuration() {
assertBothWays(Duration.ofDays(1000), "<duration>PT24000H</duration>");
assertBothWays(Duration.ofHours(50), "<duration>PT50H</duration>");
Expand Down

0 comments on commit 994e569

Please sign in to comment.