1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.joda.time.tz;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.ByteArrayOutputStream;
20 import java.io.ObjectInputStream;
21 import java.io.ObjectOutputStream;
22
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 import org.joda.time.DateTimeZone;
27
28
29
30
31
32
33 public class TestCachedDateTimeZone extends TestCase {
34
35 public static void main(String[] args) {
36 junit.textui.TestRunner.run(suite());
37 }
38
39 public static TestSuite suite() {
40 return new TestSuite(TestCachedDateTimeZone.class);
41 }
42
43 private DateTimeZone originalDateTimeZone = null;
44
45 public TestCachedDateTimeZone(String name) {
46 super(name);
47 }
48
49 protected void setUp() throws Exception {
50 originalDateTimeZone = DateTimeZone.getDefault();
51 DateTimeZone.setDefault(DateTimeZone.UTC);
52 }
53
54 protected void tearDown() throws Exception {
55 DateTimeZone.setDefault(originalDateTimeZone);
56 }
57
58 public void test_caching() throws Exception {
59 CachedDateTimeZone zone1 = CachedDateTimeZone.forZone(DateTimeZone.forID("Europe/Paris"));
60 CachedDateTimeZone zone2 = CachedDateTimeZone.forZone(DateTimeZone.forID("Europe/Paris"));
61 assertSame(zone1, zone2);
62 }
63
64
65 public void testSerialization() throws Exception {
66 CachedDateTimeZone test = CachedDateTimeZone.forZone(DateTimeZone.forID("Europe/Paris"));
67
68 ByteArrayOutputStream baos = new ByteArrayOutputStream();
69 ObjectOutputStream oos = new ObjectOutputStream(baos);
70 oos.writeObject(test);
71 byte[] bytes = baos.toByteArray();
72 oos.close();
73
74 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
75 ObjectInputStream ois = new ObjectInputStream(bais);
76 CachedDateTimeZone result = (CachedDateTimeZone) ois.readObject();
77 ois.close();
78
79 assertEquals(test, result);
80 }
81
82 }