Bring EnumUtils public constructor testing in line with main package

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137534 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-07-30 23:21:39 +00:00
parent d793a1fd62
commit 7f7d37421a
2 changed files with 21 additions and 4 deletions

View File

@ -64,14 +64,14 @@ import java.util.Map;
* @see ValuedEnum * @see ValuedEnum
* @author Stephen Colebourne * @author Stephen Colebourne
* @since 1.0 * @since 1.0
* @version $Id: EnumUtils.java,v 1.7 2003/07/14 22:25:04 bayard Exp $ * @version $Id: EnumUtils.java,v 1.8 2003/07/30 23:21:39 scolebourne Exp $
*/ */
public class EnumUtils { public class EnumUtils {
/** /**
* Restricted constructor. * Public constructor. This class should not normally be instantiated.
*/ */
private EnumUtils() { public EnumUtils() {
} }
/** /**

View File

@ -53,6 +53,8 @@
*/ */
package org.apache.commons.lang.enum; package org.apache.commons.lang.enum;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -65,7 +67,7 @@ import junit.framework.TestSuite;
* Test cases for the {@link Enum} class. * Test cases for the {@link Enum} class.
* *
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a> * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @version $Id: EnumUtilsTest.java,v 1.4 2003/07/30 23:13:09 scolebourne Exp $ * @version $Id: EnumUtilsTest.java,v 1.5 2003/07/30 23:21:39 scolebourne Exp $
*/ */
public final class EnumUtilsTest extends TestCase { public final class EnumUtilsTest extends TestCase {
@ -83,6 +85,17 @@ public final class EnumUtilsTest extends TestCase {
return suite; return suite;
} }
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new EnumUtils());
Constructor[] cons = EnumUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(EnumUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(EnumUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
public void testIterator() { public void testIterator() {
Iterator it = EnumUtils.iterator(ColorEnum.class); Iterator it = EnumUtils.iterator(ColorEnum.class);
assertSame(ColorEnum.RED, it.next()); assertSame(ColorEnum.RED, it.next());
@ -103,6 +116,7 @@ public final class EnumUtilsTest extends TestCase {
} catch (IllegalArgumentException ex) {} } catch (IllegalArgumentException ex) {}
} }
//-----------------------------------------------------------------------
public void testList() { public void testList() {
List list = EnumUtils.getEnumList(ColorEnum.class); List list = EnumUtils.getEnumList(ColorEnum.class);
Iterator it = list.iterator(); Iterator it = list.iterator();
@ -124,6 +138,7 @@ public final class EnumUtilsTest extends TestCase {
} catch (IllegalArgumentException ex) {} } catch (IllegalArgumentException ex) {}
} }
//-----------------------------------------------------------------------
public void testMap() { public void testMap() {
Map map = EnumUtils.getEnumMap(ColorEnum.class); Map map = EnumUtils.getEnumMap(ColorEnum.class);
assertTrue(map.containsValue(ColorEnum.RED)); assertTrue(map.containsValue(ColorEnum.RED));
@ -147,6 +162,7 @@ public final class EnumUtilsTest extends TestCase {
} catch (IllegalArgumentException ex) {} } catch (IllegalArgumentException ex) {}
} }
//-----------------------------------------------------------------------
public void testGet() { public void testGet() {
assertSame(ColorEnum.RED, EnumUtils.getEnum(ColorEnum.class, "Red")); assertSame(ColorEnum.RED, EnumUtils.getEnum(ColorEnum.class, "Red"));
assertSame(ColorEnum.GREEN, EnumUtils.getEnum(ColorEnum.class, "Green")); assertSame(ColorEnum.GREEN, EnumUtils.getEnum(ColorEnum.class, "Green"));
@ -166,6 +182,7 @@ public final class EnumUtilsTest extends TestCase {
} catch (IllegalArgumentException ex) {} } catch (IllegalArgumentException ex) {}
} }
//-----------------------------------------------------------------------
public void testGetValue() { public void testGetValue() {
assertSame(ValuedColorEnum.RED, EnumUtils.getEnum(ValuedColorEnum.class, 1)); assertSame(ValuedColorEnum.RED, EnumUtils.getEnum(ValuedColorEnum.class, 1));
assertSame(ValuedColorEnum.GREEN, EnumUtils.getEnum(ValuedColorEnum.class, 2)); assertSame(ValuedColorEnum.GREEN, EnumUtils.getEnum(ValuedColorEnum.class, 2));