You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dl...@apache.org on 2002/03/08 01:09:34 UTC

cvs commit: jakarta-commons-sandbox/lang/src/test/org/apache/commons/lang/exception ExceptionTestSuite.java NestableDelegateTestCase.java NestableExceptionTestCase.java NestableRuntimeExceptionTestCase.java

dlr         02/03/07 16:09:34

  Modified:    lang     build.xml
  Added:       lang/src/test/org/apache/commons/lang/exception
                        ExceptionTestSuite.java
                        NestableDelegateTestCase.java
                        NestableExceptionTestCase.java
                        NestableRuntimeExceptionTestCase.java
  Log:
  Added test cases for the exception package by Steven Caswell
  <st...@yahoo.com>.  Integrated them into the build.xml myself.
  
  Revision  Changes    Path
  1.3       +12 -2     jakarta-commons-sandbox/lang/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/build.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- build.xml	28 Feb 2002 03:06:54 -0000	1.2
  +++ build.xml	8 Mar 2002 00:09:33 -0000	1.3
  @@ -3,7 +3,7 @@
   
   <!--
           "Lang" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.2 2002/02/28 03:06:54 bayard Exp $
  +        $Id: build.xml,v 1.3 2002/03/08 00:09:33 dlr Exp $
   -->
   
   
  @@ -224,7 +224,8 @@
   
     <target name="test"  depends="compile.tests,
                                   test.strings,
  -                                test.numberRange
  +                                test.numberRange,
  +                                test.exception
                                  "
      description="Run all unit test cases">
     </target>
  @@ -244,6 +245,15 @@
       <java classname="${test.runner}" fork="yes"
           failonerror="${test.failonerror}">
         <arg value="org.apache.commons.lang.NumberRangeTest"/>
  +      <classpath refid="test.classpath"/>
  +    </java>
  +  </target>
  +
  +  <target name="test.exception" depends="compile.tests">
  +    <echo message="Running exception package tests ..."/>
  +    <java classname="${test.runner}" fork="yes"
  +        failonerror="${test.failonerror}">
  +      <arg value="org.apache.commons.lang.exception.ExceptionTestSuite"/>
         <classpath refid="test.classpath"/>
       </java>
     </target>
  
  
  
  1.1                  jakarta-commons-sandbox/lang/src/test/org/apache/commons/lang/exception/ExceptionTestSuite.java
  
  Index: ExceptionTestSuite.java
  ===================================================================
  package org.apache.commons.lang.exception;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" 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",
   *    "Apache Turbine", nor may "Apache" appear in their name, 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/>.
   */
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Test manager for the org.apache.commons.lang.exception classes.
   *
   * @author <a href="mailto:stevencaswell@yahoo.com">Steven Caswell</a>
   */
  public class ExceptionTestSuite extends TestCase
  {
      /**
       * Construct a new instance.
       */
      public ExceptionTestSuite(String name)
      {
          super(name);
      }
  
      /**
       * Command-line interface.
       */
      public static void main(String[] args)
      {
          TestRunner.run(suite());
      }
      
      public static Test suite()
      {
          TestSuite suite = new TestSuite();
          suite.addTest(NestableDelegateTestCase.suite());
          suite.addTest(NestableExceptionTestCase.suite());
          suite.addTest(NestableRuntimeExceptionTestCase.suite());
          return suite;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/lang/src/test/org/apache/commons/lang/exception/NestableDelegateTestCase.java
  
  Index: NestableDelegateTestCase.java
  ===================================================================
  package org.apache.commons.lang.exception;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" 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",
   *    "Apache Turbine", nor may "Apache" appear in their name, 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/>.
   */
  
  import java.io.ByteArrayOutputStream;
  import java.io.PrintWriter;
  import java.io.PrintStream;
  
  import junit.framework.*;
  import junit.textui.TestRunner;
  /**
   * Tests the org.apache.commons.lang.exception.NestableDelegate class.
   *
   * @author <a href="mailto:stevencaswell@yahoo.com">Steven Caswell</a>
   */
  public class NestableDelegateTestCase extends junit.framework.TestCase
  {
      private static final String CONSTRUCTOR_FAILED_MSG = 
      "The Nestable implementation passed to the NestableDelegate(Nestable) constructor must extend java.lang.Throwable";
  
      /**
       * Construct a new instance of NestableDelegateTestCase with the specified name
       */
      public NestableDelegateTestCase(String name)
      {
          super(name);
      }
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp()
      {
      }
      
      public static Test suite()
      {
          return new TestSuite(NestableDelegateTestCase.class);
      }
      
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown()
      {
      }
      
      /**
       * Test the implementation
       */
      public void testNestableDelegateConstructor()
      {
          String msg = null;
          boolean constructorFailed = false;
          try
          {
              NestableDelegate nonThrowableCause = new NestableDelegate(new NonThrowableNestable());
          }
          catch(IllegalArgumentException iae)
          {
              constructorFailed = true;
              msg = iae.getMessage();
          }
          assertTrue("nestable delegate constructor with non-throwable cause failed == true", constructorFailed);
          assertTrue("constructor failed exception msg == " + CONSTRUCTOR_FAILED_MSG,
              msg.equals(CONSTRUCTOR_FAILED_MSG));
  
          constructorFailed = false;
          try
          {
              NestableDelegate nd1 = new NestableDelegate(new ThrowableNestable());
          }
          catch(IllegalArgumentException iae)
          {
              constructorFailed = true;
          }
          assertTrue("nestable delegate constructor with throwable cause failed == false", !constructorFailed);
      }
  
      public void testNestableDelegateGetMessage()
      {
          Nestable ne1 = new ThrowableNestable();
          assertTrue("ThrowableNestable ne1 getMessage() == ThrowableNestable exception",
              ne1.getMessage().equals("ThrowableNestable exception"));
          NestableDelegate nd1 = new NestableDelegate(ne1);
          assertTrue("nd1 getMessage() == " + ne1.getCause().getMessage(),
              nd1.getMessage("base").equals("base: " + ne1.getCause().getMessage()));
          
          Nestable ne2 = new ThrowableNestedNestable(new Exception("nested exception 2"));
          NestableDelegate nd2 = new NestableDelegate(ne2);
          assertTrue("nd2 getMessage() == base: " + ne2.getCause().getMessage(),
              nd2.getMessage("base").equals("base: " + ne2.getCause().getMessage()));
      }
  
      public void testNestableDelegetePrintStackTrace()
      {
          Nestable ne3 = new ThrowableNestedNestable(new Exception("nested exception 3"));
          NestableDelegate nd3 = new NestableDelegate(ne3);
  
          ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
          PrintStream ps1 = new PrintStream(baos1);
          nd3.printStackTrace(ps1);
          String stack1 = baos1.toString();
          assertTrue("stack trace startsWith == java.lang.Exception: nested exception 3",
              stack1.startsWith("java.lang.Exception: nested exception 3"));
          int start1 = (stack1.length() - 2) - ("rethrown as ThrowableNestedNestable partial stack trace place-holder").length();
          int end1 = stack1.length() - 2;
          assertTrue("stack trace substring(" + start1 + "," + end1 + ") == rethrown as ThrowableNestedNestable partial stack trace place-holder",
              stack1.substring(start1, end1).equals("rethrown as ThrowableNestedNestable partial stack trace place-holder"));
  
          ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
          PrintStream ps2 = new PrintStream(baos2);
          System.setErr(ps2);
          nd3.printStackTrace();
          String stack2 = baos2.toString();
          assertTrue("stack trace startsWith == java.lang.Exception: nested exception 3",
              stack2.startsWith("java.lang.Exception: nested exception 3"));
          int start2 = (stack2.length() - 2) - ("rethrown as ThrowableNestedNestable partial stack trace place-holder").length();
          int end2 = stack2.length() - 2;
          assertTrue("stack trace substring(" + start2 + "," + end2 + ") == rethrown as ThrowableNestedNestable partial stack trace place-holder",
              stack2.substring(start2, end2).equals("rethrown as ThrowableNestedNestable partial stack trace place-holder"));
      }
      
      public static void main(String args[])
      {
          TestRunner.run(suite());
      }
  }
  
  class ThrowableNestable extends Throwable implements Nestable
  {
      
      /**
       * Returns the error message of this and any nested
       * <code>Throwable</code>.
       *
       * @return The error message.
       */
      public String getMessage()
      {
          return "ThrowableNestable exception";
      }
      
      /**
       * Returns the reference to the exception or error that caused the
       * exception implementing the <code>Nestable</code> to be thrown.
       */
      public Throwable getCause()
      {
          return new Exception("ThrowableNestable cause");
      }
      
      /**
       * Prints the stack trace of this exception to the specified print
       * writer.  Includes inforamation from the exception--if
       * any--which caused this exception.
       *
       * @param out <code>PrintWriter</code> to use for output.
       */
      public void printStackTrace(PrintWriter out)
      {
      }
      
      /**
       * Prints the stack trace for this exception only--root cause not
       * included--using the provided writer.  Used by {@link
       * org.apache.commons.lang.exception.NestableDelegate} to write
       * individual stack traces to a buffer.  The implementation of
       * this method should call
       * <code>super.printStackTrace(out);</code> in most cases.
       *
       * @param out The writer to use.
       */
      public void printPartialStackTrace(PrintWriter out)
      {
      }
      
  }
  
  class ThrowableNestedNestable extends Throwable implements Nestable
  {
      private Throwable cause = null;
      
      public ThrowableNestedNestable(Throwable cause)
      {
          this.cause = cause;
      }
      /**
       * Returns the error message of this and any nested
       * <code>Throwable</code>.
       *
       * @return The error message.
       */
      public String getMessage()
      {
          return "ThrowableNestedNestable exception (" + cause.getMessage() + ")";
      }
      
      /**
       * Returns the reference to the exception or error that caused the
       * exception implementing the <code>Nestable</code> to be thrown.
       */
      public Throwable getCause()
      {
          return cause;
      }
      
      /**
       * Prints the stack trace of this exception to the specified print
       * writer.  Includes inforamation from the exception--if
       * any--which caused this exception.
       *
       * @param out <code>PrintWriter</code> to use for output.
       */
      public void printStackTrace(PrintWriter out)
      {
          out.println("ThrowableNestedNestable stack trace place-holder");
      }
      
      /**
       * Prints the stack trace for this exception only--root cause not
       * included--using the provided writer.  Used by {@link
       * org.apache.commons.lang.exception.NestableDelegate} to write
       * individual stack traces to a buffer.  The implementation of
       * this method should call
       * <code>super.printStackTrace(out);</code> in most cases.
       *
       * @param out The writer to use.
       */
      public void printPartialStackTrace(PrintWriter out)
      {
          out.println("ThrowableNestedNestable partial stack trace place-holder");
      }
      
  }
  
  class NonThrowableNestable implements Nestable
  {
      /**
       * Returns the error message of this and any nested
       * <code>Throwable</code>.
       *
       * @return The error message.
       */
      public String getMessage()
      {
          return "non-throwable";
      }
      
      /**
       * Returns the reference to the exception or error that caused the
       * exception implementing the <code>Nestable</code> to be thrown.
       */
      public Throwable getCause()
      {
          return null;
      }
      
      /**
       * Prints the stack trace of this exception to the specified print
       * writer.  Includes inforamation from the exception--if
       * any--which caused this exception.
       *
       * @param out <code>PrintWriter</code> to use for output.
       */
      public void printStackTrace(PrintWriter out)
      {
      }
      
      /**
       * Prints the stack trace for this exception only--root cause not
       * included--using the provided writer.  Used by {@link
       * org.apache.commons.lang.exception.NestableDelegate} to write
       * individual stack traces to a buffer.  The implementation of
       * this method should call
       * <code>super.printStackTrace(out);</code> in most cases.
       *
       * @param out The writer to use.
       */
      public void printPartialStackTrace(PrintWriter out)
      {
      }
      
  }
  
  
  1.1                  jakarta-commons-sandbox/lang/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java
  
  Index: NestableExceptionTestCase.java
  ===================================================================
  package org.apache.commons.lang.exception;
  
  /* ====================================================================
   * 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" 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",
   *    "Apache Turbine", nor may "Apache" appear in their name, 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/>.
   */
  
  import java.io.ByteArrayOutputStream;
  import java.io.PrintStream;
  import java.io.PrintWriter;
  
  import junit.framework.*;
  import junit.textui.TestRunner;
  /**
   * Tests the org.apache.commons.lang.exception.NestableException class.
   *
   * @author <a href="mailto:stevencaswell@yahoo.com">Steven Caswell</a>
   */
  public class NestableExceptionTestCase extends junit.framework.TestCase
  {
      /**
       * Construct a new instance of NestableExceptionTestCase with the specified name
       */
      public NestableExceptionTestCase(String name)
      {
          super(name);
      }
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp()
      {
      }
      
      public static Test suite()
      {
          return new TestSuite(NestableExceptionTestCase.class);
      }
      
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown()
      {
      }
      
      /**
       * Test the implementation
       */
      public void testNestableException()
      {
          NestableException ne1 = new NestableException();
          assertNull("nestable exception() cause is null", ne1.getCause()); 
          assertNull("nestable exception() message is null", ne1.getMessage()); 
  
          NestableException ne2 = new NestableException("ne2");
          assertNull("nestable exception(\"ne2\") cause is null", ne2.getCause());
          assertNotNull("nestable exception(\"ne2\") message is not null", ne2.getMessage()); 
          assertTrue("nestable exception(\"ne2\") message == ne2", ne2.getMessage().equals("ne2")); 
  
          NestableException ne3 = new NestableException(new Exception("ne3 exception"));
          assertNotNull("nestable exception(new Exception(\"ne3 exception\") cause is not null",
              ne3.getCause()); 
          assertTrue("nestable exception(new Exception(\"ne3 exception\") cause message == ne3 exception",
              ne3.getCause().getMessage().equals("ne3 exception")); 
          assertNotNull("nestable exception(new Exception(\"ne3 exception\") message is not null",
              ne3.getMessage()); 
          assertTrue("nestable exception(new Exception(\"ne3 exception\") message == cause message",
              ne3.getMessage().equals(ne3.getCause().getMessage())); 
          
          NestableException ne4 = new NestableException("ne4", new Exception("ne4 exception"));
          assertNotNull("nestable exception(\"ne4\", new Exception(\"ne4 exception\") cause is not null", 
              ne4.getCause()); 
          assertNotNull("nestable exception(\"ne4\", new Exception(\"ne4 exception\") message is not null", 
              ne4.getMessage()); 
          assertTrue("nestable exception(\"ne4\", new Exception(\"ne4 exception\") message == ne4: ne4 exception", 
              ne4.getMessage().equals("ne4: ne4 exception")); 
  
          NestableException ne5 = new NestableException("ne5", null);
          assertNull("nestable exception(\"ne5\", null) cause is null", 
              ne5.getCause()); 
          assertNotNull("nestable exception(\"ne5\", new Exception(\"ne5 exception\") message is not null", 
              ne5.getMessage()); 
          assertTrue("nestable exception(\"ne5\", null) message == ne5", 
              ne5.getMessage().equals("ne5")); 
          
          NestableException ne6 = new NestableException(null, new Exception("ne6 exception"));
          assertNotNull("nestable exception(null, new Exception(\"ne6 exception\") cause is not null", 
              ne6.getCause()); 
          assertTrue("nestable exception(null, new Exception(\"ne6 exception\") cause == ne6 exception", 
              ne6.getMessage().equals("ne6 exception")); 
          
          NestableException ne7 = new NestableException("ne7o", new NestableException("ne7i", new Exception("ne7 exception")));
          assertTrue("nextable exception(\"ne7o\", new NestableException(\"ne7i\", new Exception(\"ne7 exception\"))) message is ne7o: ne7i: ne7 exception",
              ne7.getMessage().equals("ne7o: ne7i: ne7 exception")); 
  
          NestableException ne8 = new NestableException("ne8", new Exception("ne8 exception"));
          ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
          PrintStream ps1 = new PrintStream(baos1);
          PrintWriter pw1 = new PrintWriter(ps1, true);
          ne8.printStackTrace(ps1);
          String stack1 = baos1.toString();
          assertTrue("stack trace startsWith == java.lang.Exception: ne8 exception",
              stack1.startsWith("java.lang.Exception: ne8 exception")); 
          assertTrue("stack trace indexOf org.apache.commons.lang.exception.NestableException: ne8: ne8 exception > -1",
              stack1.indexOf("org.apache.commons.lang.exception.NestableException: ne8: ne8 exception") > -1); 
  
          NestableException ne9 = new NestableException("ne9", new Exception("ne9 exception"));
          ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
          PrintStream ps2 = new PrintStream(baos2);
          PrintWriter pw2 = new PrintWriter(ps2, true);
          ne9.printPartialStackTrace(pw2);
          String stack2 = baos2.toString();
          assertTrue("stack trace startsWith == org.apache.commons.lang.exception.NestableException: ne9: ne9 exception",
              stack2.startsWith("org.apache.commons.lang.exception.NestableException: ne9: ne9 exception"));
          assertEquals("stack trace indexOf rethrown == -1",
              stack2.indexOf("rethrown"), -1);
      }
  
      public static void main(String args[])
      {
          TestRunner.run(suite());
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/lang/src/test/org/apache/commons/lang/exception/NestableRuntimeExceptionTestCase.java
  
  Index: NestableRuntimeExceptionTestCase.java
  ===================================================================
  package org.apache.commons.lang.exception;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" 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",
   *    "Apache Turbine", nor may "Apache" appear in their name, 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/>.
   */
  
  import java.io.ByteArrayOutputStream;
  import java.io.PrintStream;
  import java.io.PrintWriter;
  
  import junit.framework.*;
  import junit.textui.TestRunner;
  /**
   * Tests the org.apache.commons.lang.exception.NestableRuntimeException class.
   *
   * @author <a href="mailto:stevencaswell@yahoo.com">Steven Caswell</a>
   */
  public class NestableRuntimeExceptionTestCase extends junit.framework.TestCase
  {
      /**
       * Construct a new instance of NestableRuntimeExceptionTestCase with the specified name
       */
      public NestableRuntimeExceptionTestCase(String name)
      {
          super(name);
      }
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp()
      {
      }
      
      public static Test suite()
      {
          return new TestSuite(NestableRuntimeExceptionTestCase.class);
      }
      
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown()
      {
      }
      
      /**
       * Test the implementation
       */
      public void testNestableRuntimeException()
      {
          NestableRuntimeException ne1 = new NestableRuntimeException();
          assertNull("nestable runtime exception() cause is null", ne1.getCause()); 
          assertNull("nestable runtime exception() message is null", ne1.getMessage()); 
  
          NestableRuntimeException ne2 = new NestableRuntimeException("ne2");
          assertNull("nestable runtime exception(\"ne2\") cause is null", ne2.getCause());
          assertNotNull("nestable runtime exception(\"ne2\") message is not null", ne2.getMessage()); 
          assertTrue("nestable runtime exception(\"ne2\") message == ne2", ne2.getMessage().equals("ne2")); 
  
          NestableRuntimeException ne3 = new NestableRuntimeException(new Exception("ne3 exception"));
          assertNotNull("nestable runtime exception(new Exception(\"ne3 exception\") cause is not null",
              ne3.getCause()); 
          assertTrue("nestable runtime exception(new Exception(\"ne3 exception\") cause message == ne3 exception",
              ne3.getCause().getMessage().equals("ne3 exception")); 
          assertNotNull("nestable runtime exception(new Exception(\"ne3 exception\") message is not null",
              ne3.getMessage());
          assertTrue("nestable runtime exception(new Exception(\"ne3 exception\") message == cause message",
              ne3.getMessage().equals(ne3.getCause().getMessage())); 
          
          NestableRuntimeException ne4 = new NestableRuntimeException("ne4", new Exception("ne4 exception"));
          assertNotNull("nestable runtime exception(\"ne4\", new Exception(\"ne4 exception\") cause is not null", 
              ne4.getCause()); 
          assertNotNull("nestable runtime exception(\"ne4\", new Exception(\"ne4 exception\") message is not null", 
              ne4.getMessage()); 
          assertTrue("nestable runtime exception(\"ne4\", new Exception(\"ne4 exception\") message == ne4: ne4 exception", 
              ne4.getMessage().equals("ne4: ne4 exception")); 
  
          NestableRuntimeException ne5 = new NestableRuntimeException("ne5", null);
          assertNull("nestable runtime exception(\"ne5\", null) cause is null", 
              ne5.getCause());
          assertNotNull("nestable runtime exception(\"ne5\", new Exception(\"ne5 exception\") message is not null", 
              ne5.getMessage()); 
          assertTrue("nestable runtime exception(\"ne5\", null) message == ne5", 
              ne5.getMessage().equals("ne5")); 
          
          NestableRuntimeException ne6 = new NestableRuntimeException(null, new Exception("ne6 exception"));
          assertNotNull("nestable runtime exception(null, new Exception(\"ne6 exception\") cause is not null", 
              ne6.getCause()); 
          assertTrue("nestable runtime exception(null, new Exception(\"ne6 exception\") cause == ne6 exception", 
              ne6.getMessage().equals("ne6 exception")); 
          
          NestableRuntimeException ne7 = new NestableRuntimeException("ne7o", new NestableRuntimeException("ne7i", new Exception("ne7 exception")));
          assertTrue("nextable exception(\"ne7o\", new NestableRuntimeException(\"ne7i\", new Exception(\"ne7 exception\"))) message is ne7o: ne7i: ne7 exception",
              ne7.getMessage().equals("ne7o: ne7i: ne7 exception")); 
  
          NestableRuntimeException ne8 = new NestableRuntimeException("ne8", new Exception("ne8 exception"));
          ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
          PrintStream ps1 = new PrintStream(baos1);
          PrintWriter pw1 = new PrintWriter(ps1, true);
          ne8.printStackTrace(ps1);
          String stack1 = baos1.toString();
          assertTrue("stack trace startsWith == java.lang.Exception: ne8 exception",
              stack1.startsWith("java.lang.Exception: ne8 exception")); 
          assertTrue("stack trace indexOf org.apache.commons.lang.exception.NestableRuntimeException: ne8: ne8 exception > -1",
              stack1.indexOf("org.apache.commons.lang.exception.NestableRuntimeException: ne8: ne8 exception") > -1); 
  
          NestableRuntimeException ne9 = new NestableRuntimeException("ne9", new Exception("ne9 exception"));
          ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
          PrintStream ps2 = new PrintStream(baos2);
          PrintWriter pw2 = new PrintWriter(ps2, true);
          ne9.printPartialStackTrace(pw2);
          String stack2 = baos2.toString();
          assertTrue("stack trace startsWith == org.apache.commons.lang.exception.NestableRuntimeException: ne9: ne9 exception",
              stack2.startsWith("org.apache.commons.lang.exception.NestableRuntimeException: ne9: ne9 exception"));
          assertEquals("stack trace indexOf rethrown == -1",
              stack2.indexOf("rethrown"), -1);
      }
  
      public static void main(String args[])
      {
          TestRunner.run(suite());
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>