stevencaswell    2003/08/06 17:50:30

  Modified:    lang/src/test/org/apache/commons/lang/exception
                        NestableExceptionTestCase.java
                        NestableRuntimeExceptionTestCase.java
  Log:
  added test coverage
  
  Revision  Changes    Path
  1.9       +38 -1     
jakarta-commons/lang/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java
  
  Index: NestableExceptionTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- NestableExceptionTestCase.java    21 May 2003 23:49:14 -0000      1.8
  +++ NestableExceptionTestCase.java    7 Aug 2003 00:50:30 -0000       1.9
  @@ -57,6 +57,7 @@
   import java.io.ByteArrayOutputStream;
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
  +import java.io.PrintStream;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -241,6 +242,42 @@
       public Class getThrowableClass()
       {
           return Exception.class;
  +    }
  +
  +    public void testSpecificPrintStackTrace()
  +    {
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream();
  +        PrintStream ps = new PrintStream(baos);
  +        NestableException ne = new NestableException("outer", new 
NestableException("inner", new Exception("another exception")));
  +        for(int i = 0; i < 2; i++)
  +        {
  +            if(i == 0)
  +            {
  +                // Test printStackTrac()
  +                // Replace System.err with our own PrintStream so that we can
  +                // obtain and check the printStrackTrace output
  +                PrintStream err = System.err;
  +                System.setErr(ps);
  +                ne.printStackTrace();
  +                // Restore the System.err
  +                System.setErr(err);
  +            }
  +            else
  +            {
  +                // Test printStackTrace(PrintStream)
  +                ne.printStackTrace(ps);
  +            }
  +        }
  +        String msg = baos.toString();
  +        assertTrue( "printStackTrace() starts with outer message", 
msg.startsWith("org.apache.commons.lang.exception.NestableException: outer"));
  +        assertTrue( "printStackTrace() contains 1st nested message", 
msg.indexOf("Caused by: org.apache.commons.lang.exception.NestableException: inner") 
>= 0);
  +        assertTrue( "printStackTrace() contains 2nd nested message", 
msg.indexOf("Caused by: java.lang.Exception: another exception") >= 0);
  +        assertTrue( "printStackTrace() inner message after outer message", 
  +            msg.indexOf("org.apache.commons.lang.exception.NestableException: 
outer") <
  +            msg.indexOf("Caused by: 
org.apache.commons.lang.exception.NestableException: inner"));
  +        assertTrue( "printStackTrace() cause message after inner message",
  +            msg.indexOf("Caused by: 
org.apache.commons.lang.exception.NestableException: inner") <
  +            msg.indexOf("Caused by: java.lang.Exception: another exception"));
       }
       
       public void testSerialization()
  
  
  
  1.8       +42 -1     
jakarta-commons/lang/src/test/org/apache/commons/lang/exception/NestableRuntimeExceptionTestCase.java
  
  Index: NestableRuntimeExceptionTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/exception/NestableRuntimeExceptionTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NestableRuntimeExceptionTestCase.java     21 May 2003 23:49:14 -0000      1.7
  +++ NestableRuntimeExceptionTestCase.java     7 Aug 2003 00:50:30 -0000       1.8
  @@ -53,6 +53,8 @@
    */
   package org.apache.commons.lang.exception;
   
  +import java.io.ByteArrayOutputStream;
  +import java.io.PrintStream;
   import junit.framework.Test;
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
  @@ -236,6 +238,45 @@
       public Class getThrowableClass()
       {
           return RuntimeException.class;
  +    }
  +    
  +    public void testSpecificPrintStackTrace()
  +    {
  +        // Test printStackTrac()
  +        // Replace System.err with our own PrintStream so that we can obtain
  +        // and check the printStrackTrace output
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream();
  +        PrintStream ps = new PrintStream(baos);
  +        NestableRuntimeException ne = new NestableRuntimeException("outer", new 
NestableRuntimeException("inner", new Exception("another exception")));
  +        for(int i = 0; i < 2; i++)
  +        {
  +            if(i == 0)
  +            {
  +                // Test printStackTrac()
  +                // Replace System.err with our own PrintStream so that we can
  +                // obtain and check the printStrackTrace output
  +                PrintStream err = System.err;
  +                System.setErr(ps);
  +                ne.printStackTrace();
  +                // Restore the System.err
  +                System.setErr(err);
  +            }
  +            else
  +            {
  +                // Test printStackTrace(PrintStream)
  +                ne.printStackTrace(ps);
  +            }
  +        }
  +        String msg = baos.toString();
  +        assertTrue( "printStackTrace() starts with outer message", 
msg.startsWith("org.apache.commons.lang.exception.NestableRuntimeException: outer"));
  +        assertTrue( "printStackTrace() contains 1st nested message", 
msg.indexOf("Caused by: org.apache.commons.lang.exception.NestableRuntimeException: 
inner") >= 0);
  +        assertTrue( "printStackTrace() contains 2nd nested message", 
msg.indexOf("Caused by: java.lang.Exception: another exception") >= 0);
  +        assertTrue( "printStackTrace() inner message after outer message", 
  +            
msg.indexOf("org.apache.commons.lang.exception.NestableRuntimeException: outer") <
  +            msg.indexOf("Caused by: 
org.apache.commons.lang.exception.NestableRuntimeException: inner"));
  +        assertTrue( "printStackTrace() cause message after inner message",
  +            msg.indexOf("Caused by: 
org.apache.commons.lang.exception.NestableRuntimeException: inner") <
  +            msg.indexOf("Caused by: java.lang.Exception: another exception"));
       }
       
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to