You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/08/03 01:22:05 UTC

svn commit: r1153304 - /maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExceptionUtilsTest.java

Author: struberg
Date: Tue Aug  2 23:22:04 2011
New Revision: 1153304

URL: http://svn.apache.org/viewvc?rev=1153304&view=rev
Log:
even more ExceptionUtilsTests

Modified:
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExceptionUtilsTest.java

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExceptionUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExceptionUtilsTest.java?rev=1153304&r1=1153303&r2=1153304&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExceptionUtilsTest.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExceptionUtilsTest.java Tue Aug  2 23:22:04 2011
@@ -28,6 +28,7 @@ import org.junit.matchers.JUnitMatchers;
 
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
+import java.util.List;
 import java.util.logging.Logger;
 
 import static org.hamcrest.CoreMatchers.*;
@@ -132,7 +133,7 @@ public class ExceptionUtilsTest extends 
             String[] methodNames = new String[]{ "getNonExistingMethod" };
 
             assertThat("getCause for InvocationTargetException"
-                    , ExceptionUtils.getCause(testException, methodNames)
+                    , ExceptionUtils.getCause( testException, methodNames )
                     , nullValue());
         }
     }
@@ -147,7 +148,7 @@ public class ExceptionUtilsTest extends 
 
         assertThat( "getFullStackTrace start with"
                   , ExceptionUtils.getFullStackTrace( npe )
-                  , JUnitMatchers.containsString(fullStackTraceStart) );
+                  , JUnitMatchers.containsString( fullStackTraceStart ) );
     }
 
     @Test
@@ -156,7 +157,7 @@ public class ExceptionUtilsTest extends 
         NullPointerException npe = new NullPointerException( "dooh just a random, nullpointer" );
         SQLException sqlException = new SQLException( npe );
         TestException testException =  new TestException();
-        testException.setSourceException(sqlException);
+        testException.setSourceException( sqlException );
 
         Throwable[] expectedExceptions = new Throwable[] { testException, sqlException, npe };
 
@@ -172,8 +173,32 @@ public class ExceptionUtilsTest extends 
     @Test
     public void testGetRootCause()
     {
-        //X TODO refine test!
-        logger.warning( "TODO implement!" );
+        NullPointerException npe = new NullPointerException( "dooh just a random, nullpointer" );
+        SQLException sqlException = new SQLException( npe );
+        TestException testException =  new TestException();
+        testException.setSourceException( sqlException );
+
+        assertThat( "getRootCause"
+                  , ExceptionUtils.getRootCause(testException)
+                  , equalTo( (Throwable) npe ) );
+
+        assertThat( "getRootCause"
+                  , ExceptionUtils.getRootCause( sqlException )
+                  , equalTo( (Throwable) npe ) );
+
+        assertThat("getRootCause"
+                , ExceptionUtils.getRootCause(npe)
+                , nullValue() );
+
+        try
+        {
+            ExceptionUtils.getRootCause( null );
+            fail( "getRootCause(null) NPE expected" );
+        }
+        catch ( NullPointerException e )
+        {
+            //nothing to do, Exception was expected
+        }
     }
 
     /**
@@ -182,6 +207,33 @@ public class ExceptionUtilsTest extends 
     @Test
     public void testGetStackFrameList()
     {
+        NullPointerException npe = new NullPointerException( "dooh just a random, nullpointer" );
+
+        List<String> exceptionFrames = ExceptionUtils.getStackFrameList( npe );
+        assertNotNull( exceptionFrames );
+        assertTrue( exceptionFrames.size() > 1 );
+        assertThat( "exceptionFrame", exceptionFrames.get( 0 )
+                  , JUnitMatchers.containsString( "at org.codehaus.plexus.util.ExceptionUtilsTest."
+                                                  + "testGetStackFrameList(ExceptionUtilsTest.java" ) );
+
+        // NPE safe test
+        try
+        {
+            ExceptionUtils.getStackFrameList( null );
+            fail( "getStackFrameList(null) NPE expected" );
+        }
+        catch ( NullPointerException e )
+        {
+            //nothing to do, Exception was expected
+        }
+    }
+
+    /**
+     * @see ExceptionUtils#getStackTrace(Throwable)
+     */
+    @Test
+    public void testGetStackTrace()
+    {
         //X TODO refine test!
         logger.warning("TODO implement!");
     }
@@ -193,8 +245,18 @@ public class ExceptionUtilsTest extends 
     @Test
     public void testGetStackFrames()
     {
-        //X TODO refine test!
-        logger.warning("TODO implement!");
+        NullPointerException npe = new NullPointerException( "dooh just a random, nullpointer" );
+
+        String[] stackFrames = ExceptionUtils.getStackFrames( npe );
+        assertNotNull( stackFrames );
+        assertTrue( stackFrames.length > 3 );
+
+        assertEquals( "java.lang.NullPointerException: " + npe.getMessage(), stackFrames[0] );
+        assertThat( "stackFrames", stackFrames[1]
+                  , JUnitMatchers.containsString( "at org.codehaus.plexus.util.ExceptionUtilsTest."
+                                                  + "testGetStackFrames(ExceptionUtilsTest.java" ) );
+
+
     }
 
     /**