You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2011/11/23 22:07:29 UTC

svn commit: r1205595 - in /maven/surefire/trunk: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ surefire-providers/surefire-junit47/src...

Author: krosenvold
Date: Wed Nov 23 21:07:28 2011
New Revision: 1205595

URL: http://svn.apache.org/viewvc?rev=1205595&view=rev
Log:
[SUREFIRE-746] NPE with failing runlisteners.

Testcase submitted by Aslak Knutsen, issues fixed by me. Testcase applied with modifications

Added:
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java   (with props)
Modified:
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterFactory.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManagerTest.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterFactory.java?rev=1205595&r1=1205594&r2=1205595&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterFactory.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterFactory.java Wed Nov 23 21:07:28 2011
@@ -155,4 +155,8 @@ public class FileReporterFactory
     {
         return globalStats;
     }
+
+    public static FileReporterFactory defaultNoXml(){
+        return new FileReporterFactory( StartupReportConfiguration.defaultNoXml() );
+    }
 }

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java?rev=1205595&r1=1205594&r2=1205595&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java Wed Nov 23 21:07:28 2011
@@ -74,7 +74,11 @@ public abstract class ConcurrentReporter
 
     public void testError( ReportEntry failure )
     {
-        getOrCreateTestMethod( failure ).testError( failure );
+        final TestMethod testMethod = getOrCreateTestMethod( failure );
+        if ( testMethod != null )
+        {
+            testMethod.testError( failure );
+        }
     }
 
     public void testSkipped( ReportEntry description )
@@ -115,7 +119,16 @@ public abstract class ConcurrentReporter
             return threadTestMethod;
         }
         TestSet testSet = getTestSet( description );
-        return testSet.createTestMethod( description );
+        if ( testSet == null )
+        {
+            consoleLogger.info( description.getName() );
+            consoleLogger.info( description.getStackTraceWriter().writeTraceToString() );
+            return null;
+        }
+        else
+        {
+            return testSet.createTestMethod( description );
+        }
     }
 
     protected abstract void checkIfTestSetCanBeReported( TestSet testSetForTest );

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManagerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManagerTest.java?rev=1205595&r1=1205594&r2=1205595&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManagerTest.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManagerTest.java Wed Nov 23 21:07:28 2011
@@ -398,7 +398,7 @@ public class ConcurrentReporterManagerTe
 
     private ReporterFactory createReporterFactory()
     {
-        return new FileReporterFactory( StartupReportConfiguration.defaultNoXml() );
+        return FileReporterFactory.defaultNoXml();
     }
 
     public static ReporterConfiguration getTestReporterConfiguration()

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java?rev=1205595&r1=1205594&r2=1205595&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java Wed Nov 23 21:07:28 2011
@@ -19,7 +19,6 @@ package org.apache.maven.surefire.junitc
 import java.io.File;
 import java.util.HashMap;
 import org.apache.maven.plugin.surefire.report.FileReporterFactory;
-import org.apache.maven.surefire.booter.StartupReportConfiguration;
 import org.apache.maven.surefire.report.DefaultConsoleReporter;
 import org.apache.maven.surefire.report.ReporterConfiguration;
 import org.apache.maven.surefire.report.ReporterFactory;
@@ -118,7 +117,7 @@ public class MavenSurefireJUnit47RunnerT
     public void testSurefireShouldBeAbleToReportRunStatusEvenWithFailingTests()
         throws Exception
     {
-        ReporterFactory reporterManagerFactory = new FileReporterFactory( StartupReportConfiguration.defaultNoXml() );
+        ReporterFactory reporterManagerFactory = FileReporterFactory.defaultNoXml( );
 
         final HashMap<String, TestSet> classMethodCounts = new HashMap<String, TestSet>();
         RunListener reporter =

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java?rev=1205595&r1=1205594&r2=1205595&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java Wed Nov 23 21:07:28 2011
@@ -19,7 +19,6 @@ package org.apache.maven.surefire.junitc
 import java.io.File;
 import java.util.HashMap;
 import org.apache.maven.plugin.surefire.report.FileReporterFactory;
-import org.apache.maven.surefire.booter.StartupReportConfiguration;
 import org.apache.maven.surefire.report.DefaultConsoleReporter;
 import org.apache.maven.surefire.report.ReporterConfiguration;
 import org.apache.maven.surefire.report.ReporterFactory;
@@ -118,7 +117,7 @@ public class MavenSurefireJUnit48RunnerT
     public void testSurefireShouldBeAbleToReportRunStatusEvenWithFailingTests()
         throws Exception
     {
-        ReporterFactory reporterManagerFactory = new FileReporterFactory( StartupReportConfiguration.defaultNoXml() );
+        ReporterFactory reporterManagerFactory = FileReporterFactory.defaultNoXml( );
 
         final HashMap<String, TestSet> classMethodCounts = new HashMap<String, TestSet>();
         RunListener reporter =

Added: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java?rev=1205595&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java (added)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java Wed Nov 23 21:07:28 2011
@@ -0,0 +1,134 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.apache.maven.surefire.junitcore;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.maven.plugin.surefire.report.FileReporterFactory;
+import org.apache.maven.surefire.booter.BaseProviderFactory;
+import org.apache.maven.surefire.report.ConsoleLogger;
+import org.apache.maven.surefire.report.DefaultConsoleReporter;
+import org.apache.maven.surefire.report.ReporterConfiguration;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.util.TestsToRun;
+
+import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.runner.Description;
+import org.junit.runner.RunWith;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.InitializationError;
+
+/**
+ * <dependency>
+ * <groupId>junit</groupId>
+ * <artifactId>junit</artifactId>
+ * <version>4.8.1</version>
+ * <scope>test</scope>
+ * </dependency>
+ * <p/>
+ * <dependency>
+ * <groupId>org.apache.maven.surefire</groupId>
+ * <artifactId>surefire-booter</artifactId>
+ * <version>2.8.1</version>
+ * <scope>test</scope>
+ * </dependency>
+ * <dependency>
+ * <groupId>org.apache.maven.plugins</groupId>
+ * <artifactId>maven-surefire-plugin</artifactId>
+ * <version>2.8.1</version>
+ * <scope>test</scope>
+ * </dependency>
+ * <dependency>
+ * <groupId>org.apache.maven.surefire</groupId>
+ * <artifactId>surefire-junit47</artifactId>
+ * <version>2.8.1</version>
+ * <scope>test</scope>
+ * </dependency>
+ *
+ * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class Surefire746Test {
+
+    @Test
+    public void surefireIsConfused_ByMultipleIgnore_OnClassLevel() throws Exception {
+        ReporterFactory reporterFactory = FileReporterFactory.defaultNoXml( );
+        BaseProviderFactory providerParameters = new BaseProviderFactory(reporterFactory, true);
+        ConsoleLogger consoleLogger = new DefaultConsoleReporter( System.out );
+
+        providerParameters.setReporterConfiguration(new ReporterConfiguration(new File(""), false));
+        Properties junitProps = new Properties();
+        junitProps.put("parallel", "none");
+
+        JUnitCoreParameters jUnitCoreParameters = new JUnitCoreParameters(junitProps);
+
+        final Map<String, TestSet> testSetMap = new ConcurrentHashMap<String, TestSet>();
+
+        RunListener listener = ConcurrentReporterManager.createInstance(testSetMap, reporterFactory, false, false, consoleLogger);
+
+        TestsToRun testsToRun = new TestsToRun(Arrays.asList(new Class[]{TestClassTest.class}));
+
+        org.junit.runner.notification.RunListener jUnit4RunListener = new JUnitCoreRunListener(listener, testSetMap);
+
+        List<org.junit.runner.notification.RunListener> customRunListeners = new ArrayList<org.junit.runner.notification.RunListener>();
+        customRunListeners.add(0, jUnit4RunListener);
+
+        JUnitCoreWrapper.execute(testsToRun, jUnitCoreParameters, customRunListeners, null);
+
+        RunResult result = reporterFactory.close();
+
+        Assert.assertEquals("JUnit should report correctly number of test ran(Finished)", 1, result.getCompletedCount());
+
+    }
+
+    @RunWith(TestCaseRunner.class)
+    public static class TestClassTest {
+        @Test
+        public void shouldNeverBeCalled() throws Exception {
+            Assert.assertTrue(true);
+        }
+    }
+
+    public static class TestCaseRunner extends BlockJUnit4ClassRunner {
+        public TestCaseRunner(Class<?> klass) throws InitializationError {
+            super(klass);
+        }
+
+        @Override
+        public void run(RunNotifier notifier) {
+            notifier.addListener(new TestRunListener());
+            super.run(notifier);
+        }
+
+    }
+
+    private static class TestRunListener extends org.junit.runner.notification.RunListener {
+        @Override
+        public void testFinished(Description description) throws Exception {
+            throw new RuntimeException("This Exception will cause Surefire to receive a internal JUnit Description and fail");
+        }
+    }
+}
\ No newline at end of file

Propchange: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java
------------------------------------------------------------------------------
    svn:eol-style = native