KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > js > junit > TypesafeEnumerationTest


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
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  */

17 package org.apache.ws.jaxme.js.junit;
18
19 import junit.framework.TestCase;
20
21
22 /** <p>This example demonstrates implementation of multiple
23  * inheritance with the ProxyGenerator. The class MyObservableList,
24  * an extension of {@link org.apache.ws.jaxme.js.junit.ObservableList},
25  * is a subclass of {@link java.util.Observable}, but can also be viewed
26  * as a subclass of {@link java.util.ArrayList} (or whatever
27  * implementation of {@link java.util.List} you choose in the constructor.
28  * The {@link java.util.Observer Observers} are notified whenever an object
29  * is added to the list.</p>
30  *
31  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
32  * @version $Id: TypesafeEnumerationTest.java,v 1.2 2004/02/16 23:39:54 jochen Exp $
33  */

34 public class TypesafeEnumerationTest extends TestCase {
35   public TypesafeEnumerationTest(String JavaDoc arg0) {
36     super(arg0);
37   }
38
39   public void testJOE() {
40      assertEquals("JOE", EnumExample.JOE.getName());
41      assertEquals("John Doe", EnumExample.JOE.getValue());
42   }
43
44   public void testPOPEYE() {
45      assertEquals("POPEYE", EnumExample.POPEYE.getName());
46      assertEquals("Olivia's Lover", EnumExample.POPEYE.getValue());
47   }
48
49   public void testDONALD() {
50      assertEquals("DONALD", EnumExample.DONALD.getName());
51      assertEquals("The Duck King", EnumExample.DONALD.getValue());
52   }
53
54   public void testgetInstanceByName() {
55      EnumExample joe = EnumExample.getInstanceByName("JOE");
56      assertEquals(joe, EnumExample.JOE);
57      assertTrue(joe == EnumExample.JOE);
58      EnumExample popeye = EnumExample.getInstanceByName("POPEYE");
59      assertEquals(popeye, EnumExample.POPEYE);
60      assertTrue(popeye == EnumExample.POPEYE);
61      EnumExample donald = EnumExample.getInstanceByName("DONALD");
62      assertEquals(donald, EnumExample.DONALD);
63      assertTrue(donald == EnumExample.DONALD);
64      Throwable JavaDoc ok = null;
65      try {
66         EnumExample.getInstanceByName("foo");
67      } catch (Throwable JavaDoc t) {
68         ok = t;
69      }
70      assertTrue(ok != null && ok instanceof IllegalArgumentException JavaDoc);
71   }
72
73   public void testgetInstanceByValue() {
74      EnumExample joe = EnumExample.getInstanceByValue("John " + "Doe");
75      assertEquals(joe, EnumExample.JOE);
76      assertTrue(joe == EnumExample.JOE);
77      EnumExample popeye = EnumExample.getInstanceByValue("Olivia's " + "Lover");
78      assertEquals(popeye, EnumExample.POPEYE);
79      assertTrue(popeye == EnumExample.POPEYE);
80      EnumExample donald = EnumExample.getInstanceByValue("The Duck" + " King");
81      assertEquals(donald, EnumExample.DONALD);
82      assertTrue(donald == EnumExample.DONALD);
83      Throwable JavaDoc ok = null;
84      try {
85         EnumExample.getInstanceByValue("bar");
86      } catch (Throwable JavaDoc t) {
87         ok = t;
88      }
89      assertTrue(ok != null && ok instanceof IllegalArgumentException JavaDoc);
90   }
91
92   public void testGetInstances() {
93      EnumExample[] instances = EnumExample.getInstances();
94      assertEquals(instances.length, 3);
95     assertEquals(EnumExample.JOE, instances[0]);
96      assertEquals(EnumExample.POPEYE, instances[1]);
97      assertEquals(EnumExample.DONALD, instances[2]);
98   }
99
100   public void testEquals() {
101      assertTrue(!EnumExample.JOE.equals(EnumExample.POPEYE));
102      assertTrue(!EnumExample.JOE.equals(EnumExample.DONALD));
103      assertTrue(!EnumExample.POPEYE.equals(EnumExample.DONALD));
104   }
105
106   public void testHashCode() {
107      assertTrue(EnumExample.JOE.hashCode() == EnumExample.JOE.getName().hashCode());
108      assertTrue(EnumExample.POPEYE.hashCode() == EnumExample.POPEYE.getName().hashCode());
109      assertTrue(EnumExample.DONALD.hashCode() == EnumExample.DONALD.getName().hashCode());
110   }
111 }
112
Popular Tags