KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > tz > TestFixedDateTimeZone


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.joda.time.tz;
17
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20
21 import org.joda.time.DateTimeZone;
22
23 /**
24  * Test cases for FixedDateTimeZone.
25  *
26  * @author Stephen Colebourne
27  */

28 public class TestFixedDateTimeZone extends TestCase {
29
30     public static void main(String JavaDoc[] args) {
31         junit.textui.TestRunner.run(suite());
32     }
33
34     public static TestSuite suite() {
35         return new TestSuite(TestFixedDateTimeZone.class);
36     }
37
38     private DateTimeZone originalDateTimeZone = null;
39
40     public TestFixedDateTimeZone(String JavaDoc name) {
41         super(name);
42     }
43
44     protected void setUp() throws Exception JavaDoc {
45         originalDateTimeZone = DateTimeZone.getDefault();
46         DateTimeZone.setDefault(DateTimeZone.UTC);
47     }
48
49     protected void tearDown() throws Exception JavaDoc {
50         DateTimeZone.setDefault(originalDateTimeZone);
51     }
52
53     public void testEquals() throws Exception JavaDoc {
54         FixedDateTimeZone zone1 = new FixedDateTimeZone("A", "B", 1, 5);
55         FixedDateTimeZone zone1b = new FixedDateTimeZone("A", "B", 1, 5);
56         FixedDateTimeZone zone2 = new FixedDateTimeZone("A", "C", 1, 5);
57         FixedDateTimeZone zone3 = new FixedDateTimeZone("A", "B", 2, 5);
58         FixedDateTimeZone zone4 = new FixedDateTimeZone("A", "B", 1, 6);
59         
60         assertEquals(true, zone1.equals(zone1));
61         assertEquals(true, zone1.equals(zone1b));
62         assertEquals(true, zone1.equals(zone2)); // second arg ignored
63
assertEquals(false, zone1.equals(zone3));
64         assertEquals(false, zone1.equals(zone4));
65     }
66
67     public void testHashCode() throws Exception JavaDoc {
68         FixedDateTimeZone zone1 = new FixedDateTimeZone("A", "B", 1, 5);
69         FixedDateTimeZone zone1b = new FixedDateTimeZone("A", "B", 1, 5);
70         FixedDateTimeZone zone2 = new FixedDateTimeZone("A", "C", 1, 5);
71         FixedDateTimeZone zone3 = new FixedDateTimeZone("A", "B", 2, 5);
72         FixedDateTimeZone zone4 = new FixedDateTimeZone("A", "B", 1, 6);
73         
74         assertEquals(true, zone1.hashCode() == zone1.hashCode());
75         assertEquals(true, zone1.hashCode() == zone1b.hashCode());
76         assertEquals(true, zone1.hashCode() == zone2.hashCode()); // second arg ignored
77
assertEquals(false, zone1.hashCode() == zone3.hashCode());
78         assertEquals(false, zone1.hashCode() == zone4.hashCode());
79     }
80
81 }
82
Popular Tags