scolebourne 2002/11/02 05:17:07
Modified: lang/src/test/org/apache/commons/lang/enum EnumTest.java
Added: lang/src/test/org/apache/commons/lang/enum Broken1Enum.java
Broken2Enum.java Broken3Enum.java
Log:
Test to ensure that duplicate enums cannot be created
Test to ensure that null and blank strings cannot be created
Bug found by Howard Lewis Ship
Revision Changes Path
1.3 +28 -1
jakarta-commons/lang/src/test/org/apache/commons/lang/enum/EnumTest.java
Index: EnumTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/enum/EnumTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EnumTest.java 13 Oct 2002 18:41:24 -0000 1.2
+++ EnumTest.java 2 Nov 2002 13:17:06 -0000 1.3
@@ -155,4 +155,31 @@
assertSame(ColorEnum.BLUE, SerializationUtils.clone(ColorEnum.BLUE));
}
+ public void testBroken1() {
+ try {
+ Broken1Enum.RED.getName();
+ fail();
+ } catch (ExceptionInInitializerError ex) {
+ assertTrue(ex.getCause() instanceof IllegalArgumentException);
+ }
+ }
+
+ public void testBroken2() {
+ try {
+ Broken2Enum.RED.getName();
+ fail();
+ } catch (ExceptionInInitializerError ex) {
+ assertTrue(ex.getCause() instanceof IllegalArgumentException);
+ }
+ }
+
+ public void testBroken3() {
+ try {
+ Broken3Enum.RED.getName();
+ fail();
+ } catch (ExceptionInInitializerError ex) {
+ assertTrue(ex.getCause() instanceof IllegalArgumentException);
+ }
+ }
+
}
1.1
jakarta-commons/lang/src/test/org/apache/commons/lang/enum/Broken1Enum.java
Index: Broken1Enum.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.lang.enum;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Broken color enumeration.
*
* @author <a href="mailto:scolebourne@;joda.org">Stephen Colebourne</a>
* @version $Id: Broken1Enum.java,v 1.1 2002/11/02 13:17:06 scolebourne Exp $
*/
public final class Broken1Enum extends Enum {
public static final Broken1Enum RED = new Broken1Enum("Red");
public static final Broken1Enum GREEN = new Broken1Enum("Green");
public static final Broken1Enum GREENISH = new Broken1Enum("Green"); //
duplicate not allowed
private Broken1Enum(String color) {
super(color);
}
public static Broken1Enum getEnum(String color) {
return (Broken1Enum) getEnum(Broken1Enum.class, color);
}
public static Map getEnumMap() {
return getEnumMap(Broken1Enum.class);
}
public static List getEnumList() {
return getEnumList(Broken1Enum.class);
}
public static Iterator iterator() {
return iterator(Broken1Enum.class);
}
}
1.1
jakarta-commons/lang/src/test/org/apache/commons/lang/enum/Broken2Enum.java
Index: Broken2Enum.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.lang.enum;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Broken color enumeration.
*
* @author <a href="mailto:scolebourne@;joda.org">Stephen Colebourne</a>
* @version $Id: Broken2Enum.java,v 1.1 2002/11/02 13:17:06 scolebourne Exp $
*/
public final class Broken2Enum extends Enum {
public static final Broken2Enum RED = new Broken2Enum("Red");
public static final Broken2Enum GREEN = new Broken2Enum("Green");
public static final Broken2Enum BLUE = new Broken2Enum(""); // blank not allowed
private Broken2Enum(String color) {
super(color);
}
public static Broken2Enum getEnum(String color) {
return (Broken2Enum) getEnum(Broken2Enum.class, color);
}
public static Map getEnumMap() {
return getEnumMap(Broken2Enum.class);
}
public static List getEnumList() {
return getEnumList(Broken2Enum.class);
}
public static Iterator iterator() {
return iterator(Broken2Enum.class);
}
}
1.1
jakarta-commons/lang/src/test/org/apache/commons/lang/enum/Broken3Enum.java
Index: Broken3Enum.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.lang.enum;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Broken color enumeration.
*
* @author <a href="mailto:scolebourne@;joda.org">Stephen Colebourne</a>
* @version $Id: Broken3Enum.java,v 1.1 2002/11/02 13:17:06 scolebourne Exp $
*/
public final class Broken3Enum extends Enum {
public static final Broken3Enum RED = new Broken3Enum("Red");
public static final Broken3Enum GREEN = new Broken3Enum("Green");
public static final Broken3Enum BLUE = new Broken3Enum(null); // null not
allowed
private Broken3Enum(String color) {
super(color);
}
public static Broken3Enum getEnum(String color) {
return (Broken3Enum) getEnum(Broken3Enum.class, color);
}
public static Map getEnumMap() {
return getEnumMap(Broken3Enum.class);
}
public static List getEnumList() {
return getEnumList(Broken3Enum.class);
}
public static Iterator iterator() {
return iterator(Broken3Enum.class);
}
}
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>