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/07/01 09:18:18 UTC

svn commit: r1141846 - in /maven/surefire/trunk: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ maven-surefire-common/src/test/java/org/apache/mav...

Author: krosenvold
Date: Fri Jul  1 07:18:17 2011
New Revision: 1141846

URL: http://svn.apache.org/viewvc?rev=1141846&view=rev
Log:
[SUREFIRE-738] add RunOrder enum

Patch submitted by Stefan Birkner, applied unchanged.

Added:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java   (with props)
    maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RunOrderTest.java   (with props)
Modified:
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
    maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/DirectoryScannerParameters.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultDirectoryScanner.java
    maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/SurefireDirectoryScannerTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/RunOrderIT.java
    maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.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=1141846&r1=1141845&r2=1141846&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 Fri Jul  1 07:18:17 2011
@@ -66,6 +66,7 @@ import org.apache.maven.surefire.testset
 import org.apache.maven.surefire.testset.TestArtifactInfo;
 import org.apache.maven.surefire.testset.TestRequest;
 import org.apache.maven.surefire.util.NestedRuntimeException;
+import org.apache.maven.surefire.util.RunOrder;
 import org.apache.maven.toolchain.Toolchain;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -369,7 +370,7 @@ public abstract class AbstractSurefireMo
             List excludes = getExcludeList();
             directoryScannerParameters = new DirectoryScannerParameters( getTestClassesDirectory(), includes, excludes,
                                                                          Boolean.valueOf( failIfNoTests ),
-                                                                         getRunOrder() );
+                                                                         getRunOrderObject() );
         }
 
         Properties providerProperties = getProperties();
@@ -1121,6 +1122,11 @@ public abstract class AbstractSurefireMo
             getLog().warn( "useSystemClassloader setting has no effect when not forking" );
         }
     }
+    
+    private RunOrder getRunOrderObject() {
+        RunOrder runOrder = RunOrder.valueOf( getRunOrder() );
+        return runOrder == null ? RunOrder.FILESYSTEM : runOrder;
+    }
 
     class TestNgProviderInfo
         implements ProviderInfo

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java?rev=1141846&r1=1141845&r2=1141846&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java Fri Jul  1 07:18:17 2011
@@ -94,7 +94,7 @@ class BooterSerializer
             properties.addList( directoryScannerParameters.getExcludes(), BooterConstants.EXCLUDES_PROPERTY_PREFIX );
             properties.setProperty( BooterConstants.TEST_CLASSES_DIRECTORY,
                                     directoryScannerParameters.getTestClassesDirectory() );
-            properties.setProperty( BooterConstants.RUN_ORDER, directoryScannerParameters.getRunOrder() );
+            properties.setProperty( BooterConstants.RUN_ORDER, directoryScannerParameters.getRunOrder().name() );
         }
 
         ReporterConfiguration reporterConfiguration = booterConfiguration.getReporterConfiguration();

Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java?rev=1141846&r1=1141845&r2=1141846&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java Fri Jul  1 07:18:17 2011
@@ -26,6 +26,10 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Properties;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
 import org.apache.maven.surefire.booter.BooterDeserializer;
 import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
 import org.apache.maven.surefire.booter.ClasspathConfiguration;
@@ -36,9 +40,7 @@ import org.apache.maven.surefire.report.
 import org.apache.maven.surefire.testset.DirectoryScannerParameters;
 import org.apache.maven.surefire.testset.TestArtifactInfo;
 import org.apache.maven.surefire.testset.TestRequest;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import org.apache.maven.surefire.util.RunOrder;
 
 /**
  * Performs roundtrip testing of serialization/deserialization of the ProviderConfiguration
@@ -158,7 +160,7 @@ public class BooterDeserializerProviderC
         excludes.add( "xx1" );
         excludes.add( "xx2" );
 
-        return new DirectoryScannerParameters( aDir, includes, excludes, Boolean.TRUE, null );
+        return new DirectoryScannerParameters( aDir, includes, excludes, Boolean.TRUE, RunOrder.FILESYSTEM );
     }
 
     private ProviderConfiguration saveAndReload( ProviderConfiguration booterConfiguration,

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java?rev=1141846&r1=1141845&r2=1141846&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java Fri Jul  1 07:18:17 2011
@@ -26,6 +26,7 @@ import java.lang.reflect.InvocationHandl
 import java.lang.reflect.Method;
 import java.util.List;
 import java.util.Properties;
+
 import org.apache.maven.plugin.surefire.report.FileReporterFactory;
 import org.apache.maven.surefire.providerapi.ProviderParameters;
 import org.apache.maven.surefire.report.ReporterConfiguration;
@@ -35,6 +36,7 @@ import org.apache.maven.surefire.testset
 import org.apache.maven.surefire.testset.TestArtifactInfo;
 import org.apache.maven.surefire.testset.TestRequest;
 import org.apache.maven.surefire.util.ReflectionUtils;
+import org.apache.maven.surefire.util.RunOrder;
 import org.apache.maven.surefire.util.SurefireReflectionException;
 
 /**
@@ -165,6 +167,7 @@ public class SurefireReflector
         {
             return null;
         }
+        //Can't use the constructor with the RunOrder parameter. Using it causes some integration tests to fail.
         Class[] arguments = { File.class, List.class, List.class, Boolean.class, String.class };
         Constructor constructor = ReflectionUtils.getConstructor( this.directoryScannerParameters, arguments );
         return ReflectionUtils.newInstance( constructor,
@@ -172,7 +175,7 @@ public class SurefireReflector
                                                 directoryScannerParameters.getIncludes(),
                                                 directoryScannerParameters.getExcludes(),
                                                 directoryScannerParameters.isFailIfNoTests(),
-                                                directoryScannerParameters.getRunOrder() } );
+                                                directoryScannerParameters.getRunOrder().name() } );
     }
 
     Object createTestArtifactInfo( TestArtifactInfo testArtifactInfo )

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/DirectoryScannerParameters.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/DirectoryScannerParameters.java?rev=1141846&r1=1141845&r2=1141846&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/DirectoryScannerParameters.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/DirectoryScannerParameters.java Fri Jul  1 07:18:17 2011
@@ -22,6 +22,8 @@ package org.apache.maven.surefire.testse
 import java.io.File;
 import java.util.List;
 
+import org.apache.maven.surefire.util.RunOrder;
+
 /**
  * @author Kristian Rosenvold
  */
@@ -35,9 +37,10 @@ public class DirectoryScannerParameters
 
     private final Boolean failIfNoTests;
 
-    private final String runOrder;
+    private final RunOrder runOrder;
 
-    public DirectoryScannerParameters( File testClassesDirectory, List includes, List excludes, Boolean failIfNoTests, String runOrder )
+    public DirectoryScannerParameters( File testClassesDirectory, List includes, List excludes, Boolean failIfNoTests,
+                                       RunOrder runOrder )
     {
         this.testClassesDirectory = testClassesDirectory;
         this.includes = includes;
@@ -46,8 +49,15 @@ public class DirectoryScannerParameters
         this.runOrder = runOrder;
     }
 
+    public DirectoryScannerParameters( File testClassesDirectory, List includes, List excludes, Boolean failIfNoTests,
+                                       String runOrder )
+    {
+        this( testClassesDirectory, includes, excludes, failIfNoTests, runOrder == null ? RunOrder.FILESYSTEM : RunOrder.valueOf( runOrder ) );
+    }
+
     /**
      * Returns the directory of the compiled classes, normally ${project.build.testOutputDirectory}
+     * 
      * @return A directory that can be scanned for .class files
      */
     public File getTestClassesDirectory()
@@ -57,6 +67,7 @@ public class DirectoryScannerParameters
 
     /**
      * The includes pattern list, as specified on the plugin includes parameter.
+     * 
      * @return A list of patterns. May contain both source file designators and .class extensions.
      */
     public List getIncludes()
@@ -66,6 +77,7 @@ public class DirectoryScannerParameters
 
     /**
      * The excludes pattern list, as specified on the plugin includes parameter.
+     * 
      * @return A list of patterns. May contain both source file designators and .class extensions.
      */
     public List getExcludes()
@@ -75,6 +87,7 @@ public class DirectoryScannerParameters
 
     /**
      * Indicates if lack of runable tests should fail the entire build
+     * 
      * @return true if no tests should fail the build
      */
     public Boolean isFailIfNoTests()
@@ -82,7 +95,7 @@ public class DirectoryScannerParameters
         return failIfNoTests;
     }
 
-    public String getRunOrder()
+    public RunOrder getRunOrder()
     {
         return runOrder;
     }

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=1141846&r1=1141845&r2=1141846&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 Fri Jul  1 07:18:17 2011
@@ -28,7 +28,7 @@ import java.util.List;
 
 /**
  * Scans directories looking for tests.
- *
+ * 
  * @author Karl M. Davis
  * @author Kristian Rosenvold
  */
@@ -54,16 +54,15 @@ public class DefaultDirectoryScanner
 
     private final Comparator sortOrder;
 
-    private final String runOrder;
+    private final RunOrder runOrder;
 
-
-    public DefaultDirectoryScanner( File basedir, List includes, List excludes, String runOrder )
+    public DefaultDirectoryScanner( File basedir, List includes, List excludes, RunOrder runOrder )
     {
         this.basedir = basedir;
         this.includes = includes;
         this.excludes = excludes;
         this.runOrder = runOrder;
-        this.sortOrder = getSortOrderComparator( runOrder );
+        this.sortOrder = getSortOrderComparator();
     }
 
     public TestsToRun locateTestClasses( ClassLoader classLoader, ScannerFilter scannerFilter )
@@ -86,14 +85,7 @@ public class DefaultDirectoryScanner
                 classesSkippedByValidation.add( testClass );
             }
         }
-        if ( "random".equals( runOrder ) )
-        {
-            Collections.shuffle( result );
-        }
-        else if ( sortOrder != null )
-        {
-            Collections.sort( result, sortOrder );
-        }
+        orderTestClasses( result );
         return new TestsToRun( result );
     }
 
@@ -111,7 +103,6 @@ public class DefaultDirectoryScanner
         return testClass;
     }
 
-
     String[] collectTests()
     {
         String[] tests = EMPTY_STRING_ARRAY;
@@ -153,10 +144,10 @@ public class DefaultDirectoryScanner
             String inc = (String) list.get( i );
             if ( inc.endsWith( JAVA_SOURCE_FILE_EXTENSION ) )
             {
-                inc = new StringBuffer(
-                    inc.length() - JAVA_SOURCE_FILE_EXTENSION.length() + JAVA_CLASS_FILE_EXTENSION.length() ).append(
-                    inc.substring( 0, inc.lastIndexOf( JAVA_SOURCE_FILE_EXTENSION ) ) ).append(
-                    JAVA_CLASS_FILE_EXTENSION ).toString();
+                inc =
+                    new StringBuffer( inc.length() - JAVA_SOURCE_FILE_EXTENSION.length()
+                        + JAVA_CLASS_FILE_EXTENSION.length() ).append( inc.substring( 0,
+                                                                                      inc.lastIndexOf( JAVA_SOURCE_FILE_EXTENSION ) ) ).append( JAVA_CLASS_FILE_EXTENSION ).toString();
             }
             incs[i] = inc;
 
@@ -169,25 +160,37 @@ public class DefaultDirectoryScanner
         return classesSkippedByValidation;
     }
 
-    private Comparator getSortOrderComparator( String runOrder )
+    private void orderTestClasses( List testClasses )
     {
-        if ( "alphabetical".equals( runOrder ) )
+        if ( RunOrder.RANDOM.equals( runOrder ) )
         {
-            return getAlphabeticalComparator();
+            Collections.shuffle( testClasses );
+        }
+        else if ( sortOrder != null )
+        {
+            Collections.sort( testClasses, sortOrder );
         }
+    }
 
-        else if ( "reversealphabetical".equals( runOrder ) )
+    private Comparator getSortOrderComparator()
+    {
+        if ( RunOrder.ALPHABETICAL.equals( runOrder ) )
+        {
+            return getAlphabeticalComparator();
+        }
+        else if ( RunOrder.REVERSE_ALPHABETICAL.equals( runOrder ) )
         {
             return getReverseAlphabeticalComparator();
         }
-        else if ( "hourly".equals( runOrder ) )
+        else if ( RunOrder.HOURLY.equals( runOrder ) )
         {
             final int hour = Calendar.getInstance().get( Calendar.HOUR_OF_DAY );
-            return ( ( hour % 2 ) == 0 )
-                ? getAlphabeticalComparator()
-                : getReverseAlphabeticalComparator();
+            return ( ( hour % 2 ) == 0 ) ? getAlphabeticalComparator() : getReverseAlphabeticalComparator();
+        }
+        else
+        {
+            return null;
         }
-        return null;
     }
 
     private Comparator getReverseAlphabeticalComparator()

Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java?rev=1141846&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java (added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java Fri Jul  1 07:18:17 2011
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.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.
+ */
+
+/**
+ * A RunOrder specifies the order in which the tests will be run.
+ * 
+ * @author Stefan Birkner
+ */
+public class RunOrder
+{
+    public static final RunOrder ALPHABETICAL = new RunOrder( "alphabetical" );
+
+    public static final RunOrder FILESYSTEM = new RunOrder( "filesystem" );
+
+    public static final RunOrder HOURLY = new RunOrder( "hourly" );
+
+    public static final RunOrder RANDOM = new RunOrder( "random" );
+
+    public static final RunOrder REVERSE_ALPHABETICAL = new RunOrder( "reversealphabetical" );
+
+    public static RunOrder valueOf( String name )
+    {
+        if ( name == null )
+        {
+            return null;
+        }
+        else
+        {
+            RunOrder[] runOrders = values();
+            for ( int i = 0; i < runOrders.length; i++ )
+            {
+                if ( runOrders[i].matches( name ) )
+                {
+                    return runOrders[i];
+                }
+            }
+
+            StringBuffer errorMessage = createMessageForMissingRunOrder( name );
+            throw new IllegalArgumentException( errorMessage.toString() );
+        }
+    }
+
+    private static StringBuffer createMessageForMissingRunOrder( String name )
+    {
+        RunOrder[] runOrders = values();
+        StringBuffer message = new StringBuffer();
+        message.append( "There's no RunOrder with the name " );
+        message.append( name );
+        message.append( ". Please use one of the following RunOrders: " );
+        for ( int i = 0; i < runOrders.length; i++ )
+        {
+            if ( i != 0 )
+            {
+                message.append( ", " );
+            }
+            message.append( runOrders[i] );
+        }
+        message.append( "." );
+        return message;
+    }
+
+    private static RunOrder[] values()
+    {
+        return new RunOrder[] { ALPHABETICAL, FILESYSTEM, HOURLY, RANDOM, REVERSE_ALPHABETICAL };
+    }
+
+    private final String name;
+
+    private RunOrder( String name )
+    {
+        this.name = name;
+    }
+
+    private boolean matches( String anotherName )
+    {
+        return name.equalsIgnoreCase( anotherName );
+    }
+
+    public String name()
+    {
+        return name;
+    }
+
+    public String toString()
+    {
+        return name;
+    }
+}
\ No newline at end of file

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

Added: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RunOrderTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RunOrderTest.java?rev=1141846&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RunOrderTest.java (added)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RunOrderTest.java Fri Jul  1 07:18:17 2011
@@ -0,0 +1,54 @@
+package org.apache.maven.surefire.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 junit.framework.TestCase;
+
+public class RunOrderTest
+    extends TestCase
+{
+    public void testShouldReturnRunOrderForLowerCaseName()
+    {
+        assertEquals( RunOrder.HOURLY, RunOrder.valueOf( "hourly" ) );
+    }
+
+    public void testShouldReturnRunOrderForUpperCaseName()
+    {
+        assertEquals( RunOrder.HOURLY, RunOrder.valueOf( "HOURLY" ) );
+    }
+
+    public void testShouldReturnNullForNullName()
+    {
+        assertNull( RunOrder.valueOf( null ) );
+    }
+
+    public void testShouldThrowExceptionForInvalidName()
+    {
+        try
+        {
+            RunOrder.valueOf( "arbitraryName" );
+            fail( "IllegalArgumentException not thrown." );
+        }
+        catch ( IllegalArgumentException expected )
+        {
+
+        }
+    }
+}
\ No newline at end of file

Propchange: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RunOrderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/SurefireDirectoryScannerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/SurefireDirectoryScannerTest.java?rev=1141846&r1=1141845&r2=1141846&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/SurefireDirectoryScannerTest.java (original)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/SurefireDirectoryScannerTest.java Fri Jul  1 07:18:17 2011
@@ -44,7 +44,7 @@ public class SurefireDirectoryScannerTes
         List exclude = new ArrayList();
 
         DefaultDirectoryScanner surefireDirectoryScanner = new DefaultDirectoryScanner( baseDir, include, exclude,
-                                                                                        "filesystem" );
+                                                                                        RunOrder.FILESYSTEM );
         String[] classNames = surefireDirectoryScanner.collectTests();
         assertNotNull( classNames );
         System.out.println("classNames " + Arrays.asList( classNames ));

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/RunOrderIT.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/RunOrderIT.java?rev=1141846&r1=1141845&r2=1141846&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/RunOrderIT.java (original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/RunOrderIT.java Fri Jul  1 07:18:17 2011
@@ -1,4 +1,5 @@
 package org.apache.maven.surefire.its;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -25,107 +26,129 @@ import org.apache.maven.surefire.its.mis
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Calendar;
-import java.util.Iterator;
 import java.util.List;
 
 /**
  * Verifies the runOrder setting and its effect
- *
+ * 
  * @author Kristian Rosenvold
  */
 public class RunOrderIT
     extends AbstractSurefireIntegrationTestClass
 {
+    private static final String[] TESTS_IN_ALPHABETICAL_ORDER = { "TA", "TB", "TC" };
+
+    private static final String[] TESTS_IN_REVERSE_ALPHABETICAL_ORDER = { "TC", "TB", "TA" };
+
     // testing random is left as an exercise to the reader. Patches welcome
 
-    public void testAlphabetical()
+    private File testDir;
+
+    private Verifier verifier;
+
+    public void setUp()
+        throws IOException, VerificationException
+    {
+        testDir = ResourceExtractor.simpleExtractResources( getClass(), "/runOrder" );
+        verifier = new Verifier( testDir.getAbsolutePath() );
+    }
+
+    public void tearDown()
         throws Exception
     {
-        checkOrder( "alphabetical", getAlphabetical() );
+        verifier.resetStreams();
     }
 
+    public void testAlphabetical()
+        throws Exception
+    {
+        executeWithRunOrder( "alphabetical" );
+        assertTestnamesAppearInSpecificOrder( TESTS_IN_ALPHABETICAL_ORDER );
+    }
 
     public void testReverseAlphabetical()
         throws Exception
     {
-        checkOrder( "reversealphabetical", getReverseAlphabetical() );
+        executeWithRunOrder( "reversealphabetical" );
+        assertTestnamesAppearInSpecificOrder( TESTS_IN_REVERSE_ALPHABETICAL_ORDER );
     }
 
-
     public void testHourly()
         throws Exception
     {
         int startHour = Calendar.getInstance().get( Calendar.HOUR_OF_DAY );
-        final List<String> actual = executeWithRunOrder( "hourly" );
+        executeWithRunOrder( "hourly" );
         int endHour = Calendar.getInstance().get( Calendar.HOUR_OF_DAY );
         if ( startHour != endHour )
         {
             return; // Race condition, cannot test when hour changed mid-run
         }
 
-        List<String> expected = ( ( startHour % 2 ) == 0 ) ? getAlphabetical() : getReverseAlphabetical();
-        if ( !contains( actual, expected ) )
-        {
-            throw new VerificationException( "Response does not contain expected item" );
-        }
+        String[] testnames =
+            ( ( startHour % 2 ) == 0 ) ? TESTS_IN_ALPHABETICAL_ORDER : TESTS_IN_REVERSE_ALPHABETICAL_ORDER;
+        assertTestnamesAppearInSpecificOrder( testnames );
     }
 
-    private boolean contains( List<String> items, List<String> expected )
+    public void testNonExistingRunOrder()
+        throws Exception
     {
-        Iterator<String> expectedIterator = expected.iterator();
-        String next = (String) expectedIterator.next();
-        Iterator<String> content = items.iterator();
-        while ( content.hasNext() )
+        try
         {
-            String line = content.next();
-            if ( line.startsWith( next ) )
-            {
-                if ( !expectedIterator.hasNext() )
-                {
-                    return true;
-                }
-                next = expectedIterator.next();
-            }
+            executeTestsWithRunOrder( "nonExistingRunOrder" );
         }
-        return content.hasNext();
-    }
-
-    private void checkOrder( String alphabetical, List<String> expected )
-        throws VerificationException, IOException
-    {
-        final List<String> list = executeWithRunOrder( alphabetical );
-        if ( !contains( list, expected ) )
+        catch ( VerificationException e )
         {
-            throw new VerificationException( "Response does not contain expected item" );
         }
+        verifier.verifyTextInLog( "There's no RunOrder with the name nonExistingRunOrder." );
     }
 
-    private List<String> executeWithRunOrder( String runOrder )
+    private void executeWithRunOrder( String runOrder )
         throws IOException, VerificationException
     {
-        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/runOrder" );
-        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        executeTestsWithRunOrder( runOrder );
+        verifier.verifyErrorFreeLog();
+        HelperAssertions.assertTestSuiteResults( 3, 0, 0, 0, testDir );
+    }
 
+    private void executeTestsWithRunOrder( String runOrder )
+        throws VerificationException
+    {
         List<String> goals = getInitialGoals();
         goals.add( "-DrunOrder=" + runOrder );
         goals.add( "test" );
-        this.executeGoals( verifier, goals );
-        verifier.verifyErrorFreeLog();
-        verifier.resetStreams();
-        HelperAssertions.assertTestSuiteResults( 3, 0, 0, 0, testDir );
-        return verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+        executeGoals( verifier, goals );
     }
 
-    private List<String> getAlphabetical()
+    private void assertTestnamesAppearInSpecificOrder( String[] testnames )
+        throws VerificationException
     {
-        return Arrays.asList( new String[]{ "TA", "TB", "TC" } );
+        if ( !testnamesAppearInSpecificOrder( testnames ) )
+        {
+            throw new VerificationException( "Response does not contain expected item" );
+        }
     }
 
-    private List<String> getReverseAlphabetical()
+    private boolean testnamesAppearInSpecificOrder( String[] testnames ) throws VerificationException
     {
-        return Arrays.asList( new String[]{ "TC", "TB", "TA" } );
+        int i = 0;
+        for ( String line : getLog() )
+        {
+            if ( line.startsWith( testnames[i] ) )
+            {
+                if ( i == testnames.length - 1 )
+                {
+                    return true;
+                }
+                ++i;
+            }
+        }
+        return false;
     }
 
+    private List<String> getLog()
+        throws VerificationException
+    {
+        return verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+    }
 }

Modified: maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?rev=1141846&r1=1141845&r2=1141846&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java Fri Jul  1 07:18:17 2011
@@ -43,6 +43,7 @@ import org.apache.maven.surefire.report.
 import org.apache.maven.surefire.testset.TestSetFailedException;
 import org.apache.maven.surefire.util.DefaultDirectoryScanner;
 import org.apache.maven.surefire.util.DirectoryScanner;
+import org.apache.maven.surefire.util.RunOrder;
 import org.apache.maven.surefire.util.TestsToRun;
 
 /**
@@ -73,7 +74,7 @@ public class TestNGDirectoryTestSuite
                                      String testMethodPattern )
     {
 
-        this.surefireDirectoryScanner = new DefaultDirectoryScanner( basedir, includes, excludes, "filesystem" );
+        this.surefireDirectoryScanner = new DefaultDirectoryScanner( basedir, includes, excludes, RunOrder.FILESYSTEM );
 
         this.options = confOptions;