1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.lang3.time;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertSame;
23 import static org.junit.jupiter.api.Assertions.assertThrows;
24
25 import java.util.TimeZone;
26
27 import org.apache.commons.lang3.SerializationUtils;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class TimeZonesGmtTest {
43
44 @Test
45 public void testCloneReturnsSelfForImmutableSingleton() {
46
47
48 final Object copy = TimeZones.GMT.clone();
49 assertSame(TimeZones.GMT, copy, "clone() of an immutable singleton should return the same instance");
50 }
51
52 @Test
53 public void testGmtIdRemainsGmtAfterAttemptedMutation() {
54 assertThrows(UnsupportedOperationException.class, () -> TimeZones.GMT.setID("Etc/UTC"));
55 assertEquals("GMT", TimeZones.GMT.getID());
56 }
57
58 @Test
59 public void testGmtOffsetRemainsZeroAfterAttemptedMutation() {
60 assertThrows(UnsupportedOperationException.class, () -> TimeZones.GMT.setRawOffset(3600000));
61 assertEquals(0, TimeZones.GMT.getRawOffset());
62 }
63
64 @Test
65 public void testGmtTimeZoneIsImmutableSetId() {
66 assertThrows(UnsupportedOperationException.class, () -> TimeZones.GMT.setID("Etc/UTC"));
67 }
68
69 @Test
70 public void testGmtTimeZoneIsImmutableSetRawOffset() {
71 assertThrows(UnsupportedOperationException.class, () -> TimeZones.GMT.setRawOffset(3600000));
72 }
73
74 @Test
75 public void testSerializationRoundTripPreservesId() throws Exception {
76
77 final TimeZone roundtrip = SerializationUtils.roundtrip(TimeZones.GMT);
78 assertNotNull(roundtrip, "Round-tripped TimeZone must not be null");
79 assertEquals("GMT", roundtrip.getID(), "Round-tripped TimeZone id must remain \"GMT\"");
80 assertEquals(0, roundtrip.getRawOffset(), "Round-tripped TimeZone offset must remain 0");
81 }
82
83 @Test
84 public void testSerializedFormUsesNamedClass() throws Exception {
85
86
87
88 assertEquals(ImmutableTimeZone.class.getName(), TimeZones.GMT.getClass().getName());
89 }
90 }