avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/util/exception/src/test/org/apache/avalon/util/exception ExceptionHelperTest.java StandardError.java StandardException.java StandardRuntimeException.java
Date Wed, 26 Nov 2003 15:35:25 GMT
mcconnell    2003/11/26 07:35:25

  Added:       merlin/util/exception/src/test/org/apache/avalon/util/exception
                        ExceptionHelperTest.java StandardError.java
                        StandardException.java
                        StandardRuntimeException.java
  Removed:     merlin/util/exception/src/java/org/apache/avalon/util/exception
                        StandardError.java StandardException.java
                        StandardRuntimeException.java
  Log:
  Add test case.
  
  Revision  Changes    Path
  1.1                  avalon/merlin/util/exception/src/test/org/apache/avalon/util/exception/ExceptionHelperTest.java
  
  Index: ExceptionHelperTest.java
  ===================================================================
  package org.apache.avalon.util.exception;
  import junit.framework.TestCase ;
  
  
  /**
   * ExceptionHelper tests.
   * 
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $
   */
  public class ExceptionHelperTest extends TestCase
  {    
      /**
       * Constructor for ExceptionHelperTest.
       * @param name
       */
      public ExceptionHelperTest( String name )
      {
          super( name );
      }
  
      final public void testCompositeExceptionReport()
          throws Exception
      {
          Throwable e1 = null;
          Throwable e2 = null;
          try
          {
              doSomething();
          }
          catch( Throwable e )
          {
              e1 = e;
          }
          try
          {
              doSomething();
          }
          catch( Throwable e )
          {
              e2 = e;
          }
          final String message = 
             ExceptionHelper.packException( 
               "Composite exception report", 
               new Throwable[]{ e1, e2 }, false );
          assertNotNull( message );
          System.out.println( message );
      }
  
      final public void testExceptionWithMessageReport()
          throws Exception
      {
          try
          {
              doSomething();
          }
          catch( Throwable e )
          {
              final String message = 
                ExceptionHelper.packException( "An error occured.", e );
              assertNotNull( message );
          }
      }
  
      final public void testExceptionWithStackTrace()
          throws Exception
      {
          try
          {
              doSomething();
          }
          catch( Throwable e )
          {
              final String message = 
                ExceptionHelper.packException( e, true );
              assertNotNull( message );
          }
      }
  
      final public void testExceptionWithMessageAndStackTrace()
          throws Exception
      {
          try
          {
              doSomething();
          }
          catch( Throwable e )
          {
              final String message = 
                ExceptionHelper.packException( "An error occured.", e, true );
              assertNotNull( message );
          }
      }
  
      private void doSomething() throws StandardException
      {
          try
          {
              doSomethingElse();
          }
          catch( Throwable e )
          {
              final String error =
                "Unable to do something due to a error condition.";
              throw new StandardException( error, e );
          }
      }
  
      private void doSomethingElse()
      {
          try
          {
              causeSomeError();
          }
          catch( Throwable e )
          {
              final String error =
                "Unable to do something else due to a error condition.";
              throw new StandardRuntimeException( error, e );
          }
      }
  
      private void causeSomeError()
      {
          final String error = 
            "Raising exception because that's what I'm programmed to do.";
          throw new StandardError( error );
      }    
  }
  
  
  
  1.1                  avalon/merlin/util/exception/src/test/org/apache/avalon/util/exception/StandardError.java
  
  Index: StandardError.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1997-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 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 "Jakarta", "Avalon", 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 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/>.
   */
  package org.apache.avalon.util.exception;
  
  /**
   * Error containing a causal exception.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/11/26 15:35:25 $
   */
  public class StandardError
      extends Error
  {
      private final Throwable m_throwable;
  
      /**
       * Construct a new <code>StandardError</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public StandardError( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>StandardError</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public StandardError( final String message, final Throwable throwable )
      {
          super( message );
          m_throwable = throwable;
      }
  
      /**
       * Retrieve root cause of the exception.
       *
       * @return the root cause
       */
      public final Throwable getCause()
      {
          return m_throwable;
      }
  }
  
  
  
  1.1                  avalon/merlin/util/exception/src/test/org/apache/avalon/util/exception/StandardException.java
  
  Index: StandardException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1997-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 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 "Jakarta", "Avalon", 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 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/>.
   */
  package org.apache.avalon.util.exception;
  
  /**
   * Exception containing a causal exception.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/11/26 15:35:25 $
   */
  public class StandardException
      extends Exception
  {
      /**
       * The Throwable that caused this exception to be thrown.
       */
      private final Throwable m_throwable;
  
      /**
       * Construct a new <code>StandardException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public StandardException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>StandardException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public StandardException( final String message, final Throwable throwable )
      {
          super( message );
          m_throwable = throwable;
      }
  
      /**
       * Retrieve root cause of the exception.
       *
       * @return the root cause
       */
      public final Throwable getCause()
      {
          return m_throwable;
      }
  }
  
  
  
  1.1                  avalon/merlin/util/exception/src/test/org/apache/avalon/util/exception/StandardRuntimeException.java
  
  Index: StandardRuntimeException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1997-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 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 "Jakarta", "Avalon", 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 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/>.
   */
  package org.apache.avalon.util.exception;
  
  /**
   * RuntimeException containing a causal exception.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/11/26 15:35:25 $
   */
  public class StandardRuntimeException
      extends RuntimeException
  {
      private final Throwable m_throwable;
  
      /**
       * Construct a new <code>StandardRuntimeException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public StandardRuntimeException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>StandardRuntimeException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public StandardRuntimeException( final String message, final Throwable throwable )
      {
          super( message );
          m_throwable = throwable;
      }
  
      /**
       * Retrieve root cause of the exception.
       *
       * @return the root cause
       */
      public final Throwable getCause()
      {
          return m_throwable;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message