01: /**
02: * $RCSfile$
03: * $Revision: 70 $
04: * $Date: 2004-10-22 10:35:36 -0700 (Fri, 22 Oct 2004) $
05: *
06: * Copyright (C) 1999-2003 CoolServlets, Inc. All rights reserved.
07: *
08: * This software is the proprietary information of CoolServlets, Inc.
09: * Use is subject to license terms.
10: */package org.jivesoftware.util;
11:
12: import junit.framework.TestCase;
13:
14: /**
15: * Simple test of the int enum class.
16: *
17: * @author Iain Shigeoka
18: */
19: public class IntEnumTest extends TestCase {
20:
21: /**
22: * Create a test case with a given name.
23: *
24: * @param name The name of the test
25: */
26: public IntEnumTest(String name) {
27: super (name);
28: }
29:
30: static public class TestIntEnum extends IntEnum {
31: public TestIntEnum(String name, int value) {
32: super (name, value);
33: register(this );
34: }
35:
36: public static TestIntEnum getTypeFromInt(int value) {
37: return (TestIntEnum) getEnumFromInt(TestIntEnum.class,
38: value);
39: }
40: }
41:
42: /**
43: * Tests the IntEnum's enforcement of unique int values for each enum type
44: */
45: public void testStaticEnumUniqueEnforcement() {
46: IntEnum e = new IntEnum("plain", 1);
47: IntEnum.register(e);
48: new TestIntEnum("test", 1); // auto registers the same value - does it clash with super class?
49: assertEquals("plain", IntEnum.getEnumFromInt(IntEnum.class, 1)
50: .getName());
51: assertEquals("test", TestIntEnum.getTypeFromInt(1).getName());
52: }
53: }
|