[SUREFIRE-1067] Nested causes conflated with wrapper exception

Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/42507889
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/42507889
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/42507889

Branch: refs/heads/master
Commit: 42507889710440d47b0885910a4b3ff3dfdd5f31
Parents: 17cb7c5
Author: Tibor17 <tibo...@lycos.com>
Authored: Fri Jul 3 00:41:44 2015 +0200
Committer: Tibor17 <tibo...@lycos.com>
Committed: Fri Jul 3 00:42:11 2015 +0200

----------------------------------------------------------------------
 .../report/SmartStackTraceParserTest.java       | 34 ++++++--
 .../report/StackTraceFocusedOnClass.java        | 86 ++++++++++++++++++++
 2 files changed, 112 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/42507889/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SmartStackTraceParserTest.java
----------------------------------------------------------------------
diff --git 
a/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SmartStackTraceParserTest.java
 
b/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SmartStackTraceParserTest.java
index bb9ffd9..4d39184 100644
--- 
a/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SmartStackTraceParserTest.java
+++ 
b/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SmartStackTraceParserTest.java
@@ -28,8 +28,7 @@ import junit.framework.AssertionFailedError;
 import junit.framework.ComparisonFailure;
 import junit.framework.TestCase;
 
-import static 
org.apache.maven.surefire.report.SmartStackTraceParser.findTopmostWithClass;
-import static 
org.apache.maven.surefire.report.SmartStackTraceParser.focusInsideClass;
+import static org.apache.maven.surefire.report.SmartStackTraceParser.*;
 
 @SuppressWarnings( "ThrowableResultOfMethodCallIgnored" )
 public class SmartStackTraceParserTest
@@ -251,7 +250,6 @@ public class SmartStackTraceParserTest
             String res = smartStackTraceParser.getString();
             assertEquals( "ATestClass X is not Z", res );
         }
-
     }
 
     public void testSingleNestedWithThread()
@@ -259,30 +257,50 @@ public class SmartStackTraceParserTest
         ExecutionException e = getSingleNested();
         String name = getClass().getName();
         Throwable focus = findTopmostWithClass( e, new 
ClassNameStackTraceFilter( name ) );
-        assertEquals( e, focus );
+        assertSame( e, focus );
         List<StackTraceElement> stackTraceElements =
             focusInsideClass( focus.getStackTrace(), new 
ClassNameStackTraceFilter( name ) );
         assertEquals( stackTraceElements.get( stackTraceElements.size() - 1 
).getClassName(), name );
     }
 
-
     public void testDoubleNestedWithThread()
     {
         ExecutionException e = getDoubleNestedException();
 
         String name = getClass().getName();
         Throwable focus = findTopmostWithClass( e, new 
ClassNameStackTraceFilter( name ) );
-        assertEquals( e, focus );
+        assertSame( e, focus );
         List<StackTraceElement> stackTraceElements =
             focusInsideClass( focus.getStackTrace(), new 
ClassNameStackTraceFilter( name ) );
         assertEquals( stackTraceElements.get( stackTraceElements.size() - 1 
).getClassName(), name );
 
-        name = "org.apache.maven.surefire.report.RunnableTestClass1";
+        name = RunnableTestClass1.class.getName();
         focus = findTopmostWithClass( e, new ClassNameStackTraceFilter( name ) 
);
-        assertEquals( e.getCause(), focus );
+        assertSame( e.getCause(), focus );
         stackTraceElements = focusInsideClass( focus.getStackTrace(), new 
ClassNameStackTraceFilter( name ) );
         assertEquals( stackTraceElements.get( stackTraceElements.size() - 1 
).getClassName(), name );
+    }
 
+    public void testStackTraceWithFocusOnClassAsString()
+    {
+        try
+        {
+            new StackTraceFocusedOnClass.C().c();
+            fail();
+        }
+        catch ( Exception e )
+        {
+            String trace = stackTraceWithFocusOnClassAsString( e, 
StackTraceFocusedOnClass.B.class.getName() );
+
+            assertEquals( "java.lang.RuntimeException: 
java.lang.IllegalStateException: java.io.IOException: I/O error\n"
+            + "\tat 
org.apache.maven.surefire.report.StackTraceFocusedOnClass$B.b(StackTraceFocusedOnClass.java:65)\n"
+            + "Caused by: java.lang.IllegalStateException: 
java.io.IOException: I/O error\n"
+            + "\tat 
org.apache.maven.surefire.report.StackTraceFocusedOnClass$B.b(StackTraceFocusedOnClass.java:61)\n"
+            + "Caused by: java.io.IOException: I/O error\n"
+            + "\tat 
org.apache.maven.surefire.report.StackTraceFocusedOnClass$B.abs(StackTraceFocusedOnClass.java:73)\n"
+            + "\tat 
org.apache.maven.surefire.report.StackTraceFocusedOnClass$B.b(StackTraceFocusedOnClass.java:61)\n",
+            trace );
+        }
     }
 
     public ExecutionException getSingleNested()

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/42507889/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/StackTraceFocusedOnClass.java
----------------------------------------------------------------------
diff --git 
a/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/StackTraceFocusedOnClass.java
 
b/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/StackTraceFocusedOnClass.java
new file mode 100644
index 0000000..64449c0
--- /dev/null
+++ 
b/surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/StackTraceFocusedOnClass.java
@@ -0,0 +1,86 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * 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 java.io.IOException;
+
+final class StackTraceFocusedOnClass
+{
+    static class JRE
+    {
+        void throwException()
+            throws IOException
+        {
+            throw new IOException( "I/O error" );
+        }
+    }
+
+    static abstract class A
+    {
+        abstract void abs()
+            throws IOException;
+
+        void a()
+        {
+            try
+            {
+                abs();
+            }
+            catch ( Exception e )
+            {
+                throw new IllegalStateException( e );
+            }
+        }
+    }
+
+    static class B extends A
+    {
+        private final JRE jre = new JRE();
+
+        void b()
+        {
+            try
+            {
+                a();
+            }
+            catch ( Exception e )
+            {
+                throw new RuntimeException( e );
+            }
+        }
+
+        @Override
+        void abs()
+            throws IOException
+        {
+            jre.throwException();
+        }
+    }
+
+    static class C
+    {
+        private final B b = new B();
+
+        void c()
+        {
+            b.b();
+        }
+    }
+}

Reply via email to