KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > util > IntEnumTest


1 /**
2  * $RCSfile: IntEnumTest.java,v $
3  * $Revision: 1.1 $
4  * $Date: 2004/10/22 17:35:36 $
5  *
6  * Copyright (C) 1999-2003 CoolServlets, Inc. All rights reserved.
7  *
8  * This software is the proprietary information of CoolServlets, Inc.
9  * Use is subject to license terms.
10  */

11 package org.jivesoftware.util;
12
13 import junit.framework.TestCase;
14
15 /**
16  * Simple test of the int enum class.
17  *
18  * @author Iain Shigeoka
19  */

20 public class IntEnumTest extends TestCase {
21
22     /**
23      * Create a test case with a given name.
24      *
25      * @param name The name of the test
26      */

27     public IntEnumTest (String JavaDoc name){
28         super(name);
29     }
30
31     static public class TestIntEnum extends IntEnum{
32         public TestIntEnum(String JavaDoc name, int value){
33             super(name,value);
34             register(this);
35         }
36         public static TestIntEnum getTypeFromInt(int value){
37             return (TestIntEnum) getEnumFromInt(TestIntEnum.class,value);
38         }
39     }
40     /**
41      * Tests the IntEnum's enforcement of unique int values for each enum type
42      */

43     public void testStaticEnumUniqueEnforcement(){
44         IntEnum e = new IntEnum("plain",1);
45         IntEnum.register(e);
46         new TestIntEnum("test",1); // auto registers the same value - does it clash with super class?
47
assertEquals("plain",IntEnum.getEnumFromInt(IntEnum.class,1).getName());
48         assertEquals("test",TestIntEnum.getTypeFromInt(1).getName());
49     }
50 }
Popular Tags