maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1043215 - in /maven/surefire/trunk: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ surefire-api/src/main/java/org/apache/maven/surefire/ surefire-api/src/main/java/org/apache/maven/surefire/providerapi/ surefire-api/...
Date Tue, 07 Dec 2010 22:17:47 GMT
Author: krosenvold
Date: Tue Dec  7 22:17:46 2010
New Revision: 1043215

URL: http://svn.apache.org/viewvc?rev=1043215&view=rev
Log:
o Pimped the junit47 provider to be reasonably best-practice

Added:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassFilter.java
  (contents, props changed)
      - copied, changed from r1042926, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassScannerFilter.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
  (with props)
Removed:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassScannerFilter.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreDirectoryTestSuite.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
Modified:
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultDirectoryScanner.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestsToRun.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestsToRunTest.java

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
(original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
Tue Dec  7 22:17:46 2010
@@ -290,11 +290,6 @@ public abstract class AbstractSurefireMo
 
             failIfNoTests = getFailIfNoTests() != null && getFailIfNoTests().booleanValue();
 
-            if ( isAnyConcurrencySelected() && isJunit47Compatible( junitArtifact
) )
-            {
-                getLog().info( "Concurrency config is " + getProperties().toString() );
-            }
-
             List includes = getIncludeList();
             List excludes = getExcludeList();
             directoryScannerParameters = new DirectoryScannerParameters( getTestClassesDirectory(),
includes, excludes,

Copied: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassFilter.java
(from r1042926, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassScannerFilter.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassFilter.java?p2=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassFilter.java&p1=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassScannerFilter.java&r1=1042926&r2=1043215&rev=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassScannerFilter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassFilter.java
Tue Dec  7 22:17:46 2010
@@ -26,7 +26,7 @@ import java.lang.reflect.Modifier;
 /**
  * @author Kristian Rosenvold
  */
-public class NonAbstractClassScannerFilter
+public class NonAbstractClassFilter
     implements ScannerFilter
 {
     public boolean accept( Class testClass )

Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/NonAbstractClassFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java
Tue Dec  7 22:17:46 2010
@@ -28,6 +28,12 @@ import java.util.Iterator;
 /**
  * Interface to be implemented by all Surefire providers.
  *
+ * Called in one of three ways:
+ * Forkmode = never: getSuites is not called, invoke is called with null parameter
+ * Forkmode = once: getSuites is not called, invoke is called with null parameter
+ * Forkmode anything else: getSuites is called, invoke is called on NEW INSTANCE for each
item in getSuites
+ * response.
+ *
  * @author Kristian Rosenvold
  */
 public interface SurefireProvider

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
Tue Dec  7 22:17:46 2010
@@ -19,7 +19,7 @@ package org.apache.maven.surefire.suite;
  * under the License.
  */
 
-import org.apache.maven.surefire.NonAbstractClassScannerFilter;
+import org.apache.maven.surefire.NonAbstractClassFilter;
 import org.apache.maven.surefire.Surefire;
 import org.apache.maven.surefire.report.ReporterManagerFactory;
 import org.apache.maven.surefire.util.DefaultDirectoryScanner;
@@ -73,7 +73,7 @@ public abstract class AbstractDirectoryT
         }
         testSets = new TreeMap();
 
-        Class[] locatedClasses = surefireDirectoryScanner.locateTestClasses( classLoader,
new NonAbstractClassScannerFilter() );
+        Class[] locatedClasses = surefireDirectoryScanner.locateTestClasses( classLoader,
new NonAbstractClassFilter() );
 
         for ( int i = 0; i < locatedClasses.length; i++ )
         {

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultDirectoryScanner.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultDirectoryScanner.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultDirectoryScanner.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultDirectoryScanner.java
Tue Dec  7 22:17:46 2010
@@ -64,15 +64,7 @@ public class DefaultDirectoryScanner
         {
             String className = testClassNames[i];
 
-            Class testClass;
-            try
-            {
-                testClass = classLoader.loadClass( className );
-            }
-            catch ( ClassNotFoundException e )
-            {
-                throw new RuntimeException( "Unable to create test class '" + className +
"'", e );
-            }
+            Class testClass = loadClass( classLoader, className );
 
             if (scannerFilter.accept( testClass)){
                 result.add( testClass );
@@ -81,6 +73,20 @@ public class DefaultDirectoryScanner
         return (Class[]) result.toArray( new Class[result.size()] );
     }
 
+    public static Class loadClass( ClassLoader classLoader, String className )
+    {
+        Class testClass;
+        try
+        {
+            testClass = classLoader.loadClass( className );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new RuntimeException( "Unable to create test class '" + className + "'",
e );
+        }
+        return testClass;
+    }
+
 
     String[] collectTests()
     {

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
Tue Dec  7 22:17:46 2010
@@ -27,9 +27,6 @@ class ConcurrentPrintStream
 {
     private final boolean isStdout;
 
-    private final LogicalStream defaultStream = new  LogicalStream();
-
-
     ConcurrentPrintStream( boolean stdout )
     {
         super( new ByteArrayOutputStream() );

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
Tue Dec  7 22:17:46 2010
@@ -94,7 +94,7 @@ class JUnitCoreParameters
     @Override
     public String toString()
     {
-        return "JUnitCoreParameters{" + "parallel='" + parallel + '\'' + ", perCoreThreadCount="
+ perCoreThreadCount +
-            ", threadCount=" + threadCount + ", useUnlimitedThreads=" + useUnlimitedThreads
+ '}';
+        return "parallel='" + parallel + '\'' + ", perCoreThreadCount=" + perCoreThreadCount
+
+            ", threadCount=" + threadCount + ", useUnlimitedThreads=" + useUnlimitedThreads;
     }
 }

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
Tue Dec  7 22:17:46 2010
@@ -19,17 +19,16 @@ package org.apache.maven.surefire.junitc
  * under the License.
  */
 
+import org.apache.maven.surefire.NonAbstractClassFilter;
 import org.apache.maven.surefire.providerapi.ProviderParameters;
 import org.apache.maven.surefire.providerapi.SurefireProvider;
 import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterManagerFactory;
-import org.apache.maven.surefire.report.RunStatistics;
 import org.apache.maven.surefire.suite.RunResult;
 import org.apache.maven.surefire.testset.TestSetFailedException;
 import org.apache.maven.surefire.util.DirectoryScanner;
 
 import java.util.Iterator;
-import java.util.Properties;
 
 /**
  * @author Kristian Rosenvold
@@ -38,61 +37,58 @@ import java.util.Properties;
 public class JUnitCoreProvider
     implements SurefireProvider
 {
-    private final Properties providerProperties;
     private final ReporterManagerFactory reporterManagerFactory;
+
     private final ClassLoader testClassLoader;
+
     private final DirectoryScanner directoryScanner;
 
+    private final JUnitCoreParameters jUnitCoreParameters;
+
+    private final NonAbstractClassFilter scannerFilter;
+
+    private TestsToRun testsToRun;
 
+    @SuppressWarnings( { "UnusedDeclaration" } )
     public JUnitCoreProvider( ProviderParameters booterParameters )
     {
         this.reporterManagerFactory = booterParameters.getReporterManagerFactory();
         this.testClassLoader = booterParameters.getTestClassLoader();
         this.directoryScanner = booterParameters.getDirectoryScanner();
-        this.providerProperties = booterParameters.getProviderProperties();
+        this.jUnitCoreParameters = new JUnitCoreParameters( booterParameters.getProviderProperties()
);
+        this.scannerFilter = new NonAbstractClassFilter();
+    }
+
+    public Boolean isRunnable()
+    {
+        return Boolean.TRUE;
     }
 
+    public Iterator getSuites()
+    {
+        testsToRun = scanClassPath();
+        return testsToRun.iterator();
+    }
 
-    @SuppressWarnings( { "UnnecessaryUnboxing" } )
     public RunResult invoke( Object forkTestSet )
         throws TestSetFailedException, ReporterException
     {
-        // Todo; Not there quite yet
-        JUnitCoreDirectoryTestSuite jUnitCoreDirectoryTestSuite = getSuite();
-
-        RunStatistics runStatistics = reporterManagerFactory.getGlobalRunStatistics();
-
-        jUnitCoreDirectoryTestSuite.locateTestSets( testClassLoader );
-        // getLog().info( "Concurrency config is " + getProperties().toString() );
+        final String message = "Concurrency config is " + jUnitCoreParameters.toString();
+        this.reporterManagerFactory.createReporterManager().writeConsoleMessage( message
);
 
-        if ( forkTestSet != null )
+        if ( testsToRun == null )
         {
-            jUnitCoreDirectoryTestSuite.execute( (String) forkTestSet, reporterManagerFactory,
-                                                 testClassLoader );
-        }
-        else
-        {
-            jUnitCoreDirectoryTestSuite.execute( reporterManagerFactory, testClassLoader
);
+            testsToRun = forkTestSet == null
+                ? scanClassPath()
+                : TestsToRun.fromClassName( (String) forkTestSet, testClassLoader );
         }
+        JUnitCoreWrapper.execute( testsToRun.getLocatedClasses(), this.reporterManagerFactory,
jUnitCoreParameters );
         reporterManagerFactory.warnIfNoTests();
-
         return reporterManagerFactory.close();
     }
 
-    private JUnitCoreDirectoryTestSuite getSuite()
-    {
-        return new JUnitCoreDirectoryTestSuite( directoryScanner, new JUnitCoreParameters(
providerProperties ),
-                                                reporterManagerFactory );
-    }
-
-    public Iterator getSuites()
+    private TestsToRun scanClassPath()
     {
-        return getSuite().locateTestSetsImpl( testClassLoader ).entrySet().iterator();
+        return new TestsToRun( directoryScanner.locateTestClasses( testClassLoader, scannerFilter
) );
     }
-
-    public Boolean isRunnable()
-    {
-        return Boolean.TRUE;
-    }
-
 }

Added: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java?rev=1043215&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
(added)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
Tue Dec  7 22:17:46 2010
@@ -0,0 +1,100 @@
+package org.apache.maven.surefire.junitcore;
+
+/*
+ * 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.surefire.report.ReporterManagerFactory;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.junit.runner.Computer;
+import org.junit.runner.JUnitCore;
+
+import java.util.concurrent.ExecutionException;
+
+/**
+ * Encapsulates access to JUnitCore
+ *
+ * @author Kristian Rosenvold
+ */
+
+class JUnitCoreWrapper
+{
+    public static void execute( Class[] classes, ReporterManagerFactory reporterManagerFactory,
+                                JUnitCoreParameters jUnitCoreParameters )
+        throws TestSetFailedException
+    {
+        final ConcurrentReportingRunListener listener =
+            ConcurrentReportingRunListener.createInstance( reporterManagerFactory,
+                                                           jUnitCoreParameters.isParallelClasses(),
+                                                           jUnitCoreParameters.isParallelBoth()
);
+        Computer computer = getComputer( jUnitCoreParameters );
+        JUnitCore junitCore = new JUnitCore();
+        junitCore.addListener( listener );
+        try
+        {
+            junitCore.run( computer, classes );
+        }
+        finally
+        {
+            junitCore.removeListener( listener );
+            closeIfConfigurable( computer );
+        }
+    }
+
+    private static void closeIfConfigurable( Computer computer )
+        throws TestSetFailedException
+    {
+        if ( computer instanceof ConfigurableParallelComputer )
+        {
+            try
+            {
+                ( (ConfigurableParallelComputer) computer ).close();
+            }
+            catch ( ExecutionException e )
+            {
+                throw new TestSetFailedException( e );
+            }
+        }
+    }
+
+    private static Computer getComputer( JUnitCoreParameters jUnitCoreParameters )
+        throws TestSetFailedException
+    {
+        if ( jUnitCoreParameters.isNoThreading() )
+        {
+            return new Computer();
+        }
+        return getConfigurableParallelComputer( jUnitCoreParameters );
+    }
+
+    private static Computer getConfigurableParallelComputer( JUnitCoreParameters JUnitCoreParameters
)
+        throws TestSetFailedException
+    {
+        if ( JUnitCoreParameters.isUseUnlimitedThreads() )
+        {
+            return new ConfigurableParallelComputer();
+        }
+        else
+        {
+            return new ConfigurableParallelComputer( JUnitCoreParameters.isParallelClasses(),
+                                                     JUnitCoreParameters.isParallelMethod(),
+                                                     JUnitCoreParameters.getThreadCount(),
+                                                     JUnitCoreParameters.isPerCoreThreadCount()
);
+        }
+    }
+}

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

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java
Tue Dec  7 22:17:46 2010
@@ -28,7 +28,6 @@ import java.util.List;
  */
 public class LogicalStream
 {
-
     private final List<Entry> output = new ArrayList<Entry>();
 
     class Entry
@@ -80,7 +79,6 @@ public class LogicalStream
         }
     }
 
-
     public void writeToConsole( ReporterManager reporter )
     {
         for ( Entry entry : output )
@@ -101,5 +99,4 @@ public class LogicalStream
         }
         return stringBuilder.toString();
     }
-
 }

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestsToRun.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestsToRun.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestsToRun.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestsToRun.java
Tue Dec  7 22:17:46 2010
@@ -21,8 +21,9 @@ package org.apache.maven.surefire.junitc
 import org.apache.maven.surefire.testset.TestSetFailedException;
 
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
 
 /**
  * Contains all the tests that have been found according to specified include/exclude
@@ -32,34 +33,46 @@ import java.util.Map;
  */
 class TestsToRun
 {
-    final Class[] locatedClasses;
+    private final Class[] locatedClasses;
 
-    final int totalTests;
-
-    Map<String, JUnitCoreTestSet> testSets;
+    private final Set<Class> testSets;
 
     public TestsToRun( Class... locatedClasses )
     {
         this.locatedClasses = locatedClasses;
-        testSets = new HashMap<String, JUnitCoreTestSet>();
-        int testCount = 0;
+        testSets = new HashSet<Class>();
         for ( Class testClass : locatedClasses )
         {
-            JUnitCoreTestSet testSet = new JUnitCoreTestSet( testClass );
-
-            if ( testSets.containsKey( testSet.getName() ) )
+            if ( testSets.contains( testClass ) )
             {
-                throw new RuntimeException( "Duplicate test set '" + testSet.getName() +
"'" );
+                throw new RuntimeException( "Duplicate test set '" + testClass.getName()
+ "'" );
             }
-            testSets.put( testSet.getName(), testSet );
-            testCount++;
+            testSets.add( testClass );
         }
-        this.totalTests = testCount;
     }
 
-    public Map<String, JUnitCoreTestSet> getTestSets()
+    private TestsToRun( String className, ClassLoader classLoader )
+        throws ClassNotFoundException
     {
-        return Collections.unmodifiableMap( testSets );
+        this( classLoader.loadClass( className ) );
+    }
+
+    public static TestsToRun fromClassName( String className, ClassLoader classLoader )
+        throws TestSetFailedException
+    {
+        try
+        {
+            return new TestsToRun( className, classLoader );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new TestSetFailedException( e );
+        }
+    }
+
+    public Set<Class> getTestSets()
+    {
+        return Collections.unmodifiableSet( testSets );
     }
 
     public int size()
@@ -72,9 +85,8 @@ class TestsToRun
         return locatedClasses;
     }
 
-    public JUnitCoreTestSet getTestSet( String name )
+    public Iterator iterator()
     {
-        return testSets.get( name );
+        return testSets.iterator();
     }
-
 }

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestsToRunTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestsToRunTest.java?rev=1043215&r1=1043214&r2=1043215&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestsToRunTest.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestsToRunTest.java
Tue Dec  7 22:17:46 2010
@@ -21,10 +21,10 @@ package org.apache.maven.surefire.junitc
 
 import org.junit.Test;
 
-import java.util.Map;
+import java.util.Set;
 
 import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
 
 /*
  * @author Kristian Rosenvold, kristian.rosenvold@gmail com
@@ -38,10 +38,8 @@ public class TestsToRunTest
     {
         TestsToRun testsToRun = new TestsToRun( T1.class, T2.class );
         assertEquals( 2, testsToRun.size() );
-        JUnitCoreTestSet coreTestSet = testsToRun.getTestSet( "org.apache.maven.surefire.junitcore.TestsToRunTest$T1"
);
-        assertNotNull( coreTestSet );
-        assertEquals( T1.class, coreTestSet.getTestClass() );
-        Map<String, JUnitCoreTestSet> stringJUnitCoreTestSetMap = testsToRun.getTestSets();
+        Set<Class> stringJUnitCoreTestSetMap = testsToRun.getTestSets();
+        assertTrue( stringJUnitCoreTestSetMap.contains( T1.class ) );
         assertEquals( 2, stringJUnitCoreTestSetMap.size() );
     }
 



Mime
View raw message