-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gary Gregory wrote:
| I only glanced at it but it is customary to provide a unit test patche
when
| adding functionality.

You're right, I forgot the src/test directory in my patch. These is the
complete patch.

- --
Alban Peignier - [EMAIL PROTECTED]
http://www.tryphon.org/~alban
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAO7mfBpsmsreMP/MRAogrAKCYlOApaRHJ1nqRCLOeoPVj3DiNkQCgiCio
/85gLIkn6wfsrkUfIttLzJM=
=ewVx
-----END PGP SIGNATURE-----
Index: src/java/org/apache/commons/lang/NotImplementedException.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/lang/src/java/org/apache/commons/lang/NotImplementedException.java,v
retrieving revision 1.6
diff -c -b -r1.6 NotImplementedException.java
*** src/java/org/apache/commons/lang/NotImplementedException.java	18 Feb 2004 22:59:49 -0000	1.6
--- src/java/org/apache/commons/lang/NotImplementedException.java	24 Feb 2004 20:48:59 -0000
***************
*** 15,20 ****
--- 15,23 ----
   */
  package org.apache.commons.lang;
  
+ import java.io.PrintStream;
+ import java.io.PrintWriter;
+ 
  /**
   * <p>Thrown to indicate that a method has not been implemented.</p>
   * 
***************
*** 24,29 ****
--- 27,35 ----
   */
  public class NotImplementedException extends UnsupportedOperationException {
  
+     /** the specified <code>Throwable</code> cause if specified in the constructor **/
+     private Throwable cause;
+ 
      /**
       * <p>Constructs the exception with the specified class.</p>
       * 
***************
*** 42,47 ****
--- 48,94 ----
       */
      public NotImplementedException(String msg) {
          super(msg);
+     }
+ 
+     /**
+      * <p>Constructs the exception with the specified message and throwable</p>
+      * 
+      * @param msg  the exception message.
+      */
+     public NotImplementedException(String msg, Throwable cause) {
+         super(msg);
+         this.cause = cause;
+     }
+ 
+     /**
+      * Returns the <code>Throwable</code> specified to the constructor.
+      */
+     public Throwable getCause() {
+         return cause;
+     }
+ 
+     /**
+      * If a <code>Throwable</code> has been provided, its stack trace is
+      * added.
+      */
+     public void printStackTrace(PrintStream s) {
+         super.printStackTrace(s);
+         if (cause != null) {
+             s.print("Unsupported Throwable: ");
+             cause.printStackTrace(s);
+         }
+     }
+ 
+     /**
+      * If a <code>Throwable</code> has been provided, its stack trace is
+      * added.
+      */
+     public void printStackTrace(PrintWriter s) {
+         super.printStackTrace(s);
+         if (cause != null) {
+             s.print("Unsupported Throwable: ");
+             cause.printStackTrace(s);
+         }
      }
  
  }
Index: src/test/org/apache/commons/lang/NotImplementedExceptionTest.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/lang/src/test/org/apache/commons/lang/NotImplementedExceptionTest.java,v
retrieving revision 1.3
diff -c -b -r1.3 NotImplementedExceptionTest.java
*** src/test/org/apache/commons/lang/NotImplementedExceptionTest.java	18 Feb 2004 23:06:19 -0000	1.3
--- src/test/org/apache/commons/lang/NotImplementedExceptionTest.java	24 Feb 2004 20:49:00 -0000
***************
*** 15,20 ****
--- 15,24 ----
   */
  package org.apache.commons.lang;
  
+ import java.io.ByteArrayOutputStream;
+ import java.io.PrintStream;
+ import java.io.PrintWriter;
+ 
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
***************
*** 53,58 ****
--- 57,68 ----
          new NotImplementedException(s);
      }
  
+     public void testConstructor_stringThrowableArg_nullInput() {
+         final String s = null;
+         final Throwable cause = null;
+         final Throwable t = new NotImplementedException(s, cause);
+     }
+ 
      // testGetMessage
  
      public void testGetMessage_classArg_nullInput() {
***************
*** 61,66 ****
--- 71,90 ----
          assertEquals("Method is not implemented in class null", t.getMessage());
      }
  
+     public void testGetMessage_stringArg_nullInput() {
+         final String s = null;
+         final Throwable t = new NotImplementedException(s);
+         assertEquals(null, t.getMessage());
+     }
+ 
+     public void testGetMessage_stringThrowableArg_nullInput() {
+         final String s = null;
+         final Throwable cause = null;
+         final Throwable t = new NotImplementedException(s, cause);
+         assertEquals(null, t.getMessage());
+         assertEquals(null, t.getCause());
+     }
+ 
      public void testGetMessage_classArg_validInput() {
          final Throwable t = new NotImplementedException(String.class);
          assertEquals(
***************
*** 68,83 ****
              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
--- 92,181 ----
              t.getMessage());
      }
  
      public void testGetMessage_stringArg_validInput() {
          final String msg = "message";
          final Throwable t = new NotImplementedException(msg);
          assertEquals(msg, t.getMessage());
+     }
+ 
+     public void testGetMessage_stringThrowableArg_validInput() {
+         final String msg = "message";
+         final Throwable cause = new Throwable();
+ 
+         final Throwable t = new NotImplementedException(msg, cause);
+         assertEquals(msg, t.getMessage());
+         assertEquals(cause, t.getCause());
+     }
+ 
+ 	// testPrintStream
+     
+     private PrintStream createNullPrintStream() {
+ 		return new PrintStream(new ByteArrayOutputStream());
+     }
+     
+     public void testPrintStackTrace() {
+ 		final String msg = "message";
+ 		final MockThrowable cause = new MockThrowable();
+ 
+ 		PrintStream originalErr = System.err;
+ 		System.setErr(createNullPrintStream());
+ 		
+ 		try {
+ 			final Throwable t = new NotImplementedException(msg, cause);
+ 			t.printStackTrace();
+ 		} finally {
+ 			System.setErr(originalErr);
+ 		}
+     	
+     	assertTrue(cause.isPrintStackTraceCalled());
+     }
+ 
+ 	public void testPrintStackTrace_printStreamArg() {
+ 		final String msg = "message";
+ 		final MockThrowable cause = new MockThrowable();
+ 
+ 		final Throwable t = new NotImplementedException(msg, cause);
+ 		t.printStackTrace(new PrintStream(new ByteArrayOutputStream()));
+     	
+ 		assertTrue(cause.isPrintStackTraceCalled());
+ 	}
+ 
+ 	public void testPrintStackTrace_printWriterArg() {
+ 		final String msg = "message";
+ 		final MockThrowable cause = new MockThrowable();
+ 
+ 		final Throwable t = new NotImplementedException(msg, cause);
+ 		t.printStackTrace(createNullPrintStream());
+     	
+ 		assertTrue(cause.isPrintStackTraceCalled());
+ 	}
+     
+     /**
+      * Used to test if the printStackTrace methods are effectively called.
+      */
+     class MockThrowable extends Throwable {
+     	
+     	private boolean printStackTraceCalled;
+     	
+     	public boolean isPrintStackTraceCalled() {
+     		return printStackTraceCalled;
+     	}
+     	
+     	public void printStackTrace() {
+     		super.printStackTrace();
+ 			printStackTraceCalled = true;
+     	}
+     	
+ 		public void printStackTrace(PrintStream p) {
+ 			super.printStackTrace(p);
+ 			printStackTraceCalled = true;
+ 		}
+ 
+ 		public void printStackTrace(PrintWriter w) {
+ 			super.printStackTrace(w);
+ 			printStackTraceCalled = true;
+ 		}
+     	 
      }
  
  } // NotImplementedExceptionTest

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

Reply via email to