maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1045361 - in /maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit: JUnit3Provider.java JUnit3TestChecker.java
Date Mon, 13 Dec 2010 20:29:24 GMT
Author: krosenvold
Date: Mon Dec 13 20:29:24 2010
New Revision: 1045361

URL: http://svn.apache.org/viewvc?rev=1045361&view=rev
Log:
[SUREFIRE-662] Fixed for junit3

Modified:
    maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java
    maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3TestChecker.java

Modified: maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java?rev=1045361&r1=1045360&r2=1045361&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java
Mon Dec 13 20:29:24 2010
@@ -19,16 +19,23 @@ package org.apache.maven.surefire.junit;
  * under the License.
  */
 
+import org.apache.maven.surefire.Surefire;
 import org.apache.maven.surefire.providerapi.ProviderParameters;
 import org.apache.maven.surefire.providerapi.SurefireProvider;
+import org.apache.maven.surefire.report.DefaultReportEntry;
+import org.apache.maven.surefire.report.ReportEntry;
 import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.ReporterManagerFactory;
+import org.apache.maven.surefire.report.ReporterManager;
 import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.testset.PojoTestSet;
+import org.apache.maven.surefire.testset.SurefireTestSet;
 import org.apache.maven.surefire.testset.TestSetFailedException;
 import org.apache.maven.surefire.util.DirectoryScanner;
+import org.apache.maven.surefire.util.TestsToRun;
 
 import java.util.Iterator;
+import java.util.ResourceBundle;
 
 /**
  * @author Kristian Rosenvold
@@ -43,45 +50,83 @@ public class JUnit3Provider
 
     private final DirectoryScanner directoryScanner;
 
+    private final JUnit3TestChecker jUnit3TestChecker;
+
+    private TestsToRun testsToRun;
+
+    private static ResourceBundle bundle = ResourceBundle.getBundle( Surefire.SUREFIRE_BUNDLE_NAME
);
+
     public JUnit3Provider( ProviderParameters booterParameters )
     {
         this.reporterFactory = booterParameters.getReporterFactory();
         this.testClassLoader = booterParameters.getTestClassLoader();
         this.directoryScanner = booterParameters.getDirectoryScanner();
+        this.jUnit3TestChecker = new JUnit3TestChecker( testClassLoader );
+
     }
 
     public RunResult invoke( Object forkTestSet )
         throws TestSetFailedException, ReporterException
     {
-        JUnitDirectoryTestSuite suite = getSuite();
-        suite.locateTestSets( testClassLoader );
-        if ( forkTestSet != null )
+        if ( testsToRun == null )
         {
-            suite.execute( (String) forkTestSet, (ReporterManagerFactory) reporterFactory,
testClassLoader );
+            testsToRun = forkTestSet == null ? scanClassPath() : TestsToRun.fromClass( (Class)
forkTestSet );
         }
-        else
+
+        for ( Iterator iter = testsToRun.iterator(); iter.hasNext();  )
         {
-            suite.execute( (ReporterManagerFactory) reporterFactory, testClassLoader );
+            Class clazz = (Class) iter.next();
+            ReporterManager reporter = (ReporterManager) reporterFactory.createReporter();
+            SurefireTestSet surefireTestSet = createTestSet(  clazz );
+            executeTestSet( surefireTestSet, reporterFactory, testClassLoader);
         }
+
         return reporterFactory.close();
     }
 
-    private JUnitDirectoryTestSuite getSuite()
+    private SurefireTestSet createTestSet( Class clazz )
+        throws TestSetFailedException
     {
-        return new JUnitDirectoryTestSuite( directoryScanner );
+        return jUnit3TestChecker.isJunit3Test( clazz )
+            ? new JUnitTestSet( clazz ) :
+            (SurefireTestSet) new PojoTestSet( clazz );
+
+    }
+
+    private void executeTestSet( SurefireTestSet testSet, ReporterFactory reporterManagerFactory,
+                                 ClassLoader classLoader )
+        throws ReporterException, TestSetFailedException
+    {
+
+        ReporterManager reporterManager = (ReporterManager) reporterManagerFactory.createReporter();
+
+        String rawString = bundle.getString( "testSetStarting" );
+
+        ReportEntry report = new DefaultReportEntry( this.getClass().getName(), testSet.getName(),
rawString );
 
+        reporterManager.testSetStarting( report );
+
+        testSet.execute( reporterManager, classLoader );
+
+        rawString = bundle.getString( "testSetCompletedNormally" );
+
+        report = new DefaultReportEntry( this.getClass().getName(), testSet.getName(), rawString
);
+
+        reporterManager.testSetCompleted( report );
+
+        reporterManager.reset();
     }
 
+    private TestsToRun scanClassPath()
+    {
+        return directoryScanner.locateTestClasses( testClassLoader, jUnit3TestChecker );
+    }
+
+
     public Iterator getSuites()
     {
-        try
-        {
-            return getSuite().locateTestSets( testClassLoader ).keySet().iterator();
-        }
-        catch ( TestSetFailedException e )
-        {
-            throw new RuntimeException( e );
-        }
+        testsToRun = scanClassPath();
+        return testsToRun.iterator();
     }
 
     public Boolean isRunnable()

Modified: maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3TestChecker.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3TestChecker.java?rev=1045361&r1=1045360&r2=1045361&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3TestChecker.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3TestChecker.java
Mon Dec 13 20:29:24 2010
@@ -1,4 +1,5 @@
 package org.apache.maven.surefire.junit;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,9 +19,12 @@ package org.apache.maven.surefire.junit;
  * under the License.
  */
 
+import org.apache.maven.surefire.NonAbstractClassFilter;
 import org.apache.maven.surefire.util.ReflectionUtils;
 import org.apache.maven.surefire.util.ScannerFilter;
 
+import java.lang.reflect.Modifier;
+
 /**
  * @author Kristian Rosenvold
  */
@@ -29,6 +33,8 @@ public class JUnit3TestChecker
 {
     private final Class junitClass;
 
+    private final NonAbstractClassFilter nonAbstractClassFilter = new NonAbstractClassFilter();
+
 
     public JUnit3TestChecker( ClassLoader testClassLoader )
     {
@@ -37,16 +43,20 @@ public class JUnit3TestChecker
 
     public boolean accept( Class testClass )
     {
-        return isValidJUnit3Test( testClass );
+        return nonAbstractClassFilter.accept(  testClass ) && isValidJUnit3Test(
testClass );
     }
 
     public boolean isValidJUnit3Test( Class testClass )
     {
-        return junitClass != null && junitClass.isAssignableFrom( testClass ) ||
-            classHasPublicNoArgConstructor( testClass );
+        return isJunit3Test( testClass ) || isPojoTest( testClass );
+    }
+
+    public boolean isJunit3Test( Class testClass )
+    {
+        return junitClass != null && junitClass.isAssignableFrom( testClass );
     }
 
-    private boolean classHasPublicNoArgConstructor( Class testClass )
+    private boolean isPojoTest( Class testClass )
     {
         try
         {



Mime
View raw message