You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2003/05/15 06:05:12 UTC
cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang IllegalClassExceptionTest.java IncompleteArgumentExceptionTest.java NotImplementedExceptionTest.java NullArgumentExceptionTest.java UnhandledExceptionTest.java LangTestSuite.java
bayard 2003/05/14 21:05:11
Modified: lang/src/test/org/apache/commons/lang LangTestSuite.java
Added: lang/src/java/org/apache/commons/lang
IllegalClassException.java
IncompleteArgumentException.java
NotImplementedException.java
NullArgumentException.java UnhandledException.java
lang/src/test/org/apache/commons/lang
IllegalClassExceptionTest.java
IncompleteArgumentExceptionTest.java
NotImplementedExceptionTest.java
NullArgumentExceptionTest.java
UnhandledExceptionTest.java
Log:
Commonly usable enhancements to some of the Exceptions found in java.lang.
Submitted by: Matthew Hawthorne
Revision Changes Path
1.1 jakarta-commons/lang/src/java/org/apache/commons/lang/IllegalClassException.java
Index: IllegalClassException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
/**
* Thrown when an object is an instance of an unexpected class.
*
* @author Matthew Hawthorne
* @version $Id: IllegalClassException.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
*/
public class IllegalClassException extends IllegalArgumentException {
/**
* Instantiates with the specified classes.
* @param expected the expected type
* @param actual the actual type
*/
public IllegalClassException(Class expected, Class actual) {
super(
"Expected: "
+ safeGetClassName(expected)
+ ", Actual: "
+ safeGetClassName(actual));
}
/**
* Instantiates with the specified classes.
* @param message the exception message
*/
public IllegalClassException(String message) {
super(message);
}
/**
* Gets a classname without throwing an Exception.
* @param c a <code>Class</code>
* @return the name of <code>c</code>, or a <code>null</code> <code>String</code>
*/
private static final String safeGetClassName(Class c) {
return c == null ? null : c.getName();
}
}
1.1 jakarta-commons/lang/src/java/org/apache/commons/lang/IncompleteArgumentException.java
Index: IncompleteArgumentException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
import java.util.Arrays;
/**
* Thrown to indicate an incomplete argument to a method.
*
* @author Matthew Hawthorne
* @version $Id: IncompleteArgumentException.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
*/
public class IncompleteArgumentException extends IllegalArgumentException {
/**
* Instantiates with the specified description.
* @param argName a description of the incomplete argument
*/
public IncompleteArgumentException(String argName) {
super(argName + " is incomplete.");
}
/**
* Instantiates with the specified description.
* @param item a description of the incomplete argument
*/
public IncompleteArgumentException(String argName, String[] items) {
super(
argName
+ " is missing the following items: "
+ safeArrayToString(items));
}
/**
* Converts an array to a string without throwing an exception.
* @param array an array
* @return the array as a string
*/
private static final String safeArrayToString(Object[] array) {
return array == null ? null : Arrays.asList(array).toString();
}
}
1.1 jakarta-commons/lang/src/java/org/apache/commons/lang/NotImplementedException.java
Index: NotImplementedException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
/**
* Thrown to indicate that a method has not been implemented.
*
* @author Matthew Hawthorne
* @version $Id: NotImplementedException.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
*/
public class NotImplementedException extends UnsupportedOperationException {
/**
* Instantites with the specified class.
* @param clazz the <code>Class</code> that has not implemented the method
*/
public NotImplementedException(Class clazz) {
super(
"Method is not implemented in class "
+ ((clazz == null) ? null : clazz.getName()));
}
/**
* Instantites with the specified msg.
* @param msg the exception message.
*/
public NotImplementedException(String msg) {
super(msg);
}
}
1.1 jakarta-commons/lang/src/java/org/apache/commons/lang/NullArgumentException.java
Index: NullArgumentException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
/**
* Thrown to indicate that an argument was null and should not have been.
*
* @author Matthew Hawthorne
* @version $Id: NullArgumentException.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
*/
public class NullArgumentException extends IllegalArgumentException {
/**
* Instantiates with the given argument name.
* @param argName - the name of the argument that was null.
*/
public NullArgumentException(String argName) {
super(argName + " cannot be null.");
}
}
1.1 jakarta-commons/lang/src/java/org/apache/commons/lang/UnhandledException.java
Index: UnhandledException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
import org.apache.commons.lang.exception.NestableRuntimeException;
/**
* Thrown when it is impossible or undesirable to consume
* or throw a checked exception.
*
* @author Matthew Hawthorne
* @version $Id: UnhandledException.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
*/
public class UnhandledException extends NestableRuntimeException {
public UnhandledException(Throwable cause) {
super(cause);
}
public UnhandledException(String message, Throwable cause) {
super(message, cause);
}
}
1.16 +7 -1 jakarta-commons/lang/src/test/org/apache/commons/lang/LangTestSuite.java
Index: LangTestSuite.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/LangTestSuite.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- LangTestSuite.java 15 Apr 2003 14:29:01 -0000 1.15
+++ LangTestSuite.java 15 May 2003 04:05:11 -0000 1.16
@@ -63,6 +63,7 @@
*
* @author Stephen Colebourne
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
+ * @author Matthew Hawthorne
* @version $Id$
*/
public class LangTestSuite extends TestCase {
@@ -91,6 +92,10 @@
suite.addTest(BooleanUtilsTest.suite());
suite.addTest(CharSetUtilsTest.suite());
suite.addTest(ClassUtilsTest.suite());
+ suite.addTest(IllegalClassExceptionTest.suite());
+ suite.addTest(IncompleteArgumentExceptionTest.suite());
+ suite.addTest(NotImplementedExceptionTest.suite());
+ suite.addTest(NullArgumentExceptionTest.suite());
suite.addTest(NumberRangeTest.suite());
suite.addTest(NumberUtilsTest.suite());
suite.addTest(ObjectUtilsTest.suite());
@@ -102,6 +107,7 @@
suite.addTest(StringUtilsEqualsIndexOfTest.suite());
suite.addTest(StringUtilsIsTest.suite());
suite.addTest(StringEscapeUtilsTest.suite());
+ suite.addTest(UnhandledExceptionTest.suite());
suite.addTest(WordWrapUtilsTest.suite());
return suite;
}
1.1 jakarta-commons/lang/src/test/org/apache/commons/lang/IllegalClassExceptionTest.java
Index: IllegalClassExceptionTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* JUnit tests.
*
* @author Matthew Hawthorne
* @version $Id: IllegalClassExceptionTest.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
* @see IllegalClassException
*/
public class IllegalClassExceptionTest extends TestCase {
public static void main(String[] args) {
TestRunner.run(suite());
}
public static Test suite() {
return new TestSuite(IllegalClassExceptionTest.class);
}
public IllegalClassExceptionTest(String testName) {
super(testName);
}
// testConstructor_classArgs
public void testConstructor_classArgs_allNullInput() {
new IllegalClassException(null, null);
}
public void testConstructor_classArgs_nullExpected() {
new IllegalClassException(null, String.class);
}
public void testConstructor_classArgs_nullActual() {
new IllegalClassException(String.class, null);
}
// testConstructor_stringArg
public void testConstructor_stringArg_nullInput() {
new IllegalClassException(null);
}
// testGetMessage
public void testGetMessage_classArgs_nullInput() {
final Throwable t = new IllegalClassException(null, null);
assertEquals("Expected: null, Actual: null", t.getMessage());
}
public void testGetMessage_classArgs_normalInput() {
final Throwable t =
new IllegalClassException(String.class, Integer.class);
assertEquals(
"Expected: java.lang.String, Actual: java.lang.Integer",
t.getMessage());
}
public void testGetMessage_stringArg_nullInput() {
final Throwable t = new IllegalClassException(null);
assertEquals(null, t.getMessage());
}
public void testGetMessage_stringArg_validInput() {
final String message = "message";
final Throwable t = new IllegalClassException(message);
assertEquals(message, t.getMessage());
}
} // IllegalClassExceptionTest
1.1 jakarta-commons/lang/src/test/org/apache/commons/lang/IncompleteArgumentExceptionTest.java
Index: IncompleteArgumentExceptionTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* JUnit tests.
*
* @author Matthew Hawthorne
* @version $Id: IncompleteArgumentExceptionTest.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
* @see IncompleteArgumentException
*/
public class IncompleteArgumentExceptionTest extends TestCase {
public static void main(String[] args) {
TestRunner.run(suite());
}
public static Test suite() {
return new TestSuite(IncompleteArgumentExceptionTest.class);
}
public IncompleteArgumentExceptionTest(String testName) {
super(testName);
}
// testConstructor
public void test1arg_nullInput() {
final Throwable t = new IncompleteArgumentException(null);
assertEquals("null is incomplete.", t.getMessage());
}
public void test1arg_validInput() {
final String name = "argument";
final Throwable t = new IncompleteArgumentException(name);
assertEquals(name + " is incomplete.", t.getMessage());
}
public void test2arg_allNullInput() {
final Throwable t = new IncompleteArgumentException(null, null);
assertEquals(
"null is missing the following items: null",
t.getMessage());
}
public void test2arg_nullString() {
final Throwable t =
new IncompleteArgumentException(
null,
new String[] { "one", "two" });
assertEquals(
"null is missing the following items: [one, two]",
t.getMessage());
}
public void test2arg_nullArray() {
final String name = "one";
final Throwable t = new IncompleteArgumentException(name, null);
assertEquals(
name + " is missing the following items: null",
t.getMessage());
}
public void test2arg_validInput() {
final String name = "input";
final Throwable t =
new IncompleteArgumentException(
name,
new String[] { "one", "two" });
assertEquals(
name + " is missing the following items: [one, two]",
t.getMessage());
}
} // IncompleteArgumentExceptionTest
1.1 jakarta-commons/lang/src/test/org/apache/commons/lang/NotImplementedExceptionTest.java
Index: NotImplementedExceptionTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* JUnit tests.
*
* @author Matthew Hawthorne
* @version $Id: NotImplementedExceptionTest.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
* @see NotImplementedException
*/
public class NotImplementedExceptionTest extends TestCase {
public static void main(String[] args) {
TestRunner.run(suite());
}
public static Test suite() {
return new TestSuite(NotImplementedExceptionTest.class);
}
public NotImplementedExceptionTest(String testName) {
super(testName);
}
// testConstructor
public void testConstructor_classArg_nullInput() {
final Class c = null;
new NotImplementedException(c);
}
public void testConstructor_stringArg_nullInput() {
final String s = null;
new NotImplementedException(s);
}
// testGetMessage
public void testGetMessage_classArg_nullInput() {
final Class c = null;
final Throwable t = new NotImplementedException(c);
assertEquals("Method is not implemented in class null", t.getMessage());
}
public void testGetMessage_classArg_validInput() {
final Throwable t = new NotImplementedException(String.class);
assertEquals(
"Method is not implemented in class java.lang.String",
t.getMessage());
}
public void testGetMessage_stringArg_nullInput() {
final String s = null;
final Throwable t = new NotImplementedException(s);
assertEquals(null, t.getMessage());
}
public void testGetMessage_stringArg_validInput() {
final String msg = "message";
final Throwable t = new NotImplementedException(msg);
assertEquals(msg, t.getMessage());
}
} // NotImplementedExceptionTest
1.1 jakarta-commons/lang/src/test/org/apache/commons/lang/NullArgumentExceptionTest.java
Index: NullArgumentExceptionTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* JUnit tests.
*
* @author Matthew Hawthorne
* @version $Id: NullArgumentExceptionTest.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
* @see NullArgumentException
*/
public class NullArgumentExceptionTest extends TestCase {
public static void main(String[] args) {
TestRunner.run(suite());
}
public static Test suite() {
return new TestSuite(NullArgumentExceptionTest.class);
}
public NullArgumentExceptionTest(String testName) {
super(testName);
}
// testConstructor
public void testConstructor_nullInput() {
new NullArgumentException(null);
}
// testGetMessage
public void testGetMessage_nullConstructorInput() {
final Throwable t = new NullArgumentException(null);
assertEquals("null cannot be null.", t.getMessage());
}
public void testGetMessage_validConstructorInput() {
final String argName = "name";
final Throwable t = new NullArgumentException(argName);
assertEquals(argName + " cannot be null.", t.getMessage());
}
} // NullArgumentExceptionTest
1.1 jakarta-commons/lang/src/test/org/apache/commons/lang/UnhandledExceptionTest.java
Index: UnhandledExceptionTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 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 apache@apache.org.
*
* 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;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.commons.lang.exception.Nestable;
/**
* JUnit tests.
*
* @author Matthew Hawthorne
* @version $Id: UnhandledExceptionTest.java,v 1.1 2003/05/15 04:05:11 bayard Exp $
* @see UnhandledException
*/
public class UnhandledExceptionTest extends TestCase {
public static void main(String[] args) {
TestRunner.run(suite());
}
public static Test suite() {
return new TestSuite(UnhandledExceptionTest.class);
}
public UnhandledExceptionTest(String testName) {
super(testName);
}
// testConstructor
public void testConstructor_throwable_nullInput() {
final Throwable t = null;
new UnhandledException(t);
}
public void testConstructor_stringAndThrowable_nullInput() {
new UnhandledException(null, null);
}
// testGetCause
public void testGetCause() {
final Throwable t = new NullPointerException();
final Nestable n = new UnhandledException(t);
assertEquals(t, n.getCause());
}
public void testGetCauseAndGetMessage() {
final Throwable t = new NullPointerException();
final String msg = "nullArg";
final Nestable n = new UnhandledException(msg, t);
assertEquals(t, n.getCause());
assertEquals(msg, n.getMessage());
}
} // UnhandledExceptionTest
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org