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 00:44:18 UTC

svn commit: r1153297 - in /maven/sandbox/trunk/plexus-utils-commons-bridge: plexus-utils-commons-bridge/ plexus-utils-tck/ plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ plexus-utils-tck/src/test/java/org/codehaus/plexus/util/exceptionutils/

Author: struberg
Date: Tue Aug  2 22:44:17 2011
New Revision: 1153297

URL: http://svn.apache.org/viewvc?rev=1153297&view=rev
Log:
add first version of ExceptionUtils TCK

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

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml?rev=1153297&r1=1153296&r2=1153297&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml Tue Aug  2 22:44:17 2011
@@ -41,12 +41,12 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-	 <groupId>com.google.guava</groupId>
-	 <artifactId>guava</artifactId>
-	 <version>r09</version>
-	 <scope>test</scope>
-	</dependency>
-	<dependency>
+    <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>r09</version>
+      <scope>test</scope>
+    </dependency>
+      <dependency>
      <groupId>org.javolution</groupId>
      <artifactId>javolution</artifactId>
      <version>5.2.6</version>

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/pom.xml?rev=1153297&r1=1153296&r2=1153297&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/pom.xml (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/pom.xml Tue Aug  2 22:44:17 2011
@@ -1,55 +1,55 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
 
-	<parent>
-		<artifactId>plexus-utils-commons-bridge-parent</artifactId>
-		<groupId>org.apache.maven.sandbox</groupId>
-		<version>0.1-SNAPSHOT</version>
-	</parent>
-
-	<artifactId>plexus-utils-tck</artifactId>
-
-	<name>Plexus Utils Test Compatibility Kit</name>
-	<description>A set of test cases that verify compatibility with the Plexus Utils API</description>
-
-	<dependencies>
-		<dependency>
-			<groupId>org.codehaus.plexus</groupId>
-			<artifactId>plexus-utils</artifactId>
-			<version>2.0.7</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>4.8.2</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>com.google.guava</groupId>
-			<artifactId>guava</artifactId>
-			<version>r09</version>
-			<scope>test</scope>
-		</dependency>
-
-	</dependencies>
-
-	<build>
-		<plugins>
-			<plugin>
-				<artifactId>maven-jar-plugin</artifactId>
-				<executions>
-					<execution>
-						<goals>
-							<goal>test-jar</goal>
-						</goals>
-					</execution>
-				</executions>
-			</plugin>
-		</plugins>
-	</build>
+    <parent>
+        <artifactId>plexus-utils-commons-bridge-parent</artifactId>
+        <groupId>org.apache.maven.sandbox</groupId>
+        <version>0.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>plexus-utils-tck</artifactId>
+
+    <name>Plexus Utils Test Compatibility Kit</name>
+    <description>A set of test cases that verify compatibility with the Plexus Utils API</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-utils</artifactId>
+            <version>2.0.7</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>r09</version>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 
 
 </project>

Added: 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=1153297&view=auto
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExceptionUtilsTest.java (added)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExceptionUtilsTest.java Tue Aug  2 22:44:17 2011
@@ -0,0 +1,243 @@
+package org.codehaus.plexus.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.tck.FixPlexusBugs;
+import org.codehaus.plexus.util.exceptionutils.TestException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.Assert;
+import org.junit.matchers.JUnitMatchers;
+
+import java.lang.reflect.InvocationTargetException;
+import java.sql.SQLException;
+import java.util.logging.Logger;
+
+import static org.hamcrest.CoreMatchers.*;
+
+
+/**
+ * Test all public methods of {@link ExceptionUtils}.
+ *
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class ExceptionUtilsTest extends Assert
+{
+    private static Logger logger = Logger.getLogger(ExceptionUtilsTest.class.getName());
+
+    @Rule
+    public FixPlexusBugs fixPlexusBugs = new FixPlexusBugs();
+
+    protected static StackTraceElement[] STACKTRACE_WO_SPECIAL_METHODS =
+        {
+            new StackTraceElement("org.apache.maven.test.Class1", "method1", null, 101),
+            new StackTraceElement("org.apache.maven.test.Class2", "method2", null, 101),
+            new StackTraceElement("org.apache.maven.test.Class3", "method3", null, 101),
+            new StackTraceElement("org.apache.maven.test.Class4", "method4", null, 101),
+        };
+
+
+    /**
+     * Hack, who invokes a state-changing static method?
+     * That's SICK!
+     * We should deprecate this very method.
+     */
+    @Test
+    public void testAddCauseMethodName()
+    {
+        ExceptionUtils.addCauseMethodName( "getNestedException" );
+
+        //X TODO refine test!
+    }
+
+
+
+
+    @Test
+    public void testGetCause()
+    {
+        NullPointerException npe = new NullPointerException( "dooh just a random, nullpointer" );
+
+        {
+            Exception exception = new Exception( npe );
+            exception.setStackTrace(STACKTRACE_WO_SPECIAL_METHODS);
+            assertThat( "getCause for custom Exception is the same as before"
+                      , ExceptionUtils.getCause( exception )
+                      , equalTo( (Throwable) npe ) );
+        }
+
+        {
+            SQLException sqlException1 = new SQLException();
+            SQLException sqlException2 = new SQLException();
+            sqlException1.setNextException(sqlException2);
+
+            assertThat( "getCause for SQLException"
+                      , ExceptionUtils.getCause( sqlException1 )
+                      , equalTo( (Throwable) sqlException2 ) );
+        }
+
+        {
+            InvocationTargetException ivte = new InvocationTargetException( npe );
+
+            assertThat( "getCause for InvocationTargetException"
+                      , ExceptionUtils.getCause( ivte )
+                      , equalTo( (Throwable) npe ) );
+        }
+
+        {
+            TestException testException = new TestException();
+            testException.setSourceException( npe );
+
+            assertThat( "getCause for InvocationTargetException"
+                      , ExceptionUtils.getCause( testException )
+                      , equalTo( (Throwable) npe ) );
+        }
+    }
+
+    @Test
+    public void testGetCause_MethodNames()
+    {
+        NullPointerException npe = new NullPointerException( "dooh just a random, nullpointer" );
+
+        {
+            TestException testException = new TestException();
+            testException.setSpecialCause( npe );
+            String[] methodNames = new String[]{ "getSpecialCause" };
+
+            assertThat( "getCause for InvocationTargetException"
+                      , ExceptionUtils.getCause( testException, methodNames )
+                      , equalTo( (Throwable) npe ) );
+        }
+
+        {
+            TestException testException = new TestException();
+            testException.setSpecialCause( npe );
+            String[] methodNames = new String[]{ "getNonExistingMethod" };
+
+            assertThat("getCause for InvocationTargetException"
+                    , ExceptionUtils.getCause(testException, methodNames)
+                    , nullValue());
+        }
+    }
+
+    @Test
+    public void testGetFullStackTrace()
+    {
+        NullPointerException npe = new NullPointerException( "dooh just a random, nullpointer" );
+
+        String fullStackTraceStart = "java.lang.NullPointerException: dooh just a random, nullpointer\n"
+                     + "\tat org.codehaus.plexus.util.ExceptionUtilsTest.testGetFullStackTrace(ExceptionUtilsTest.java";
+
+        assertThat( "getFullStackTrace start with"
+                  , ExceptionUtils.getFullStackTrace( npe )
+                  , JUnitMatchers.containsString(fullStackTraceStart) );
+    }
+
+    @Test
+    public void testGetThrowables()
+    {
+        NullPointerException npe = new NullPointerException( "dooh just a random, nullpointer" );
+        SQLException sqlException = new SQLException( npe );
+        TestException testException =  new TestException();
+        testException.setSourceException(sqlException);
+
+        Throwable[] expectedExceptions = new Throwable[] { testException, sqlException, npe };
+
+        assertThat( "getThrowables"
+                  , ExceptionUtils.getThrowables( testException )
+                  , equalTo( expectedExceptions ) );
+    }
+
+
+    /**
+     * @see ExceptionUtils#getRootCause(Throwable)
+     */
+    @Test
+    public void testGetRootCause()
+    {
+        //X TODO refine test!
+        logger.warning( "TODO implement!" );
+    }
+
+    /**
+     * @see ExceptionUtils#getStackFrameList(Throwable)
+     */
+    @Test
+    public void testGetStackFrameList()
+    {
+        //X TODO refine test!
+        logger.warning("TODO implement!");
+    }
+
+    /**
+     * @see ExceptionUtils#getStackFrames(Throwable)
+     * @see ExceptionUtils#getStackFrames(String)
+     */
+    @Test
+    public void testGetStackFrames()
+    {
+        //X TODO refine test!
+        logger.warning("TODO implement!");
+    }
+
+    /**
+     * @see ExceptionUtils#getThrowableCount(Throwable)
+     */
+    @Test
+    public void testGetThrowableCount()
+    {
+        //X TODO refine test!
+        logger.warning("TODO implement!");
+    }
+
+    /**
+     * @see ExceptionUtils#indexOfThrowable(Throwable, Class)
+     * @see ExceptionUtils#indexOfThrowable(Throwable, Class, int)
+     */
+    @Test
+    public void testIndexOfThrowable()
+    {
+        //X TODO refine test!
+        logger.warning("TODO implement!");
+    }
+
+    /**
+     * @see ExceptionUtils#isNestedThrowable(Throwable)
+     */
+    @Test
+    public void testIsNestedThrowable()
+    {
+        //X TODO refine test!
+        logger.warning("TODO implement!");
+    }
+
+    /**
+     * @see ExceptionUtils#printRootCauseStackTrace(Throwable)
+     * @see ExceptionUtils#printRootCauseStackTrace(Throwable, java.io.PrintWriter)
+     * @see ExceptionUtils#printRootCauseStackTrace(Throwable, java.io.PrintStream)
+     */
+    @Test
+    public void testPrintRootCauseStackTrace()
+    {
+        //X TODO refine test!
+        logger.warning("TODO implement!");
+    }
+
+}

Added: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/exceptionutils/TestException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/exceptionutils/TestException.java?rev=1153297&view=auto
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/exceptionutils/TestException.java (added)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/exceptionutils/TestException.java Tue Aug  2 22:44:17 2011
@@ -0,0 +1,58 @@
+package org.codehaus.plexus.util.exceptionutils;
+
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+
+/**
+ *
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class TestException extends Exception
+{
+    private Throwable cause;
+    private Throwable specialCause;
+
+    public TestException()
+    {
+        super();
+    }
+
+    public void setSourceException( Throwable cause )
+    {
+        this.cause = cause;
+    }
+
+    public Throwable getSourceException()
+    {
+        return cause;
+    }
+
+    public Throwable getSpecialCause()
+    {
+        return specialCause;
+    }
+
+    public void setSpecialCause( Throwable specialCause )
+    {
+        this.specialCause = specialCause;
+    }
+}