IntEnumTest.java 1.42 KB
Newer Older
Bill Lynch's avatar
Bill Lynch committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
6
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch committed
7
 *
8 9 10
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
Bill Lynch's avatar
Bill Lynch committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
 */
package org.jivesoftware.util;

import junit.framework.TestCase;

/**
 * Simple test of the int enum class.
 *
 * @author Iain Shigeoka
 */
public class IntEnumTest extends TestCase {

    /**
     * Create a test case with a given name.
     *
     * @param name The name of the test
     */
    public IntEnumTest (String name){
        super(name);
    }

    static public class TestIntEnum extends IntEnum{
        public TestIntEnum(String name, int value){
            super(name,value);
            register(this);
        }
        public static TestIntEnum getTypeFromInt(int value){
            return (TestIntEnum) getEnumFromInt(TestIntEnum.class,value);
        }
    }
    /**
     * Tests the IntEnum's enforcement of unique int values for each enum type
     */
    public void testStaticEnumUniqueEnforcement(){
        IntEnum e = new IntEnum("plain",1);
        IntEnum.register(e);
        new TestIntEnum("test",1); // auto registers the same value - does it clash with super class?
        assertEquals("plain",IntEnum.getEnumFromInt(IntEnum.class,1).getName());
        assertEquals("test",TestIntEnum.getTypeFromInt(1).getName());
    }
}