Author: olamy
Date: Tue Feb 28 10:46:43 2012
New Revision: 1294568

URL: http://svn.apache.org/viewvc?rev=1294568&view=rev
Log:
[SUREFIRE-745] -Dtest supports multiple test classes but not multiple test 
methods.
Submitted by rainLee .

Added:
    
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMultipleMethodsIT.java
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/pom.xml
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/BasicTest.java
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestThree.java
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestTwo.java
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/pom.xml
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/BasicTest.java
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestThree.java
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestTwo.java
   (with props)
Modified:
    
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
    
maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java

Modified: 
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=1294568&r1=1294567&r2=1294568&view=diff
==============================================================================
--- 
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
 (original)
+++ 
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
 Tue Feb 28 10:46:43 2012
@@ -19,11 +19,6 @@ package org.apache.maven.plugin.surefire
  * under the License.
  */
 
-import java.io.File;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@@ -39,6 +34,12 @@ import org.apache.maven.surefire.suite.R
 import org.apache.maven.toolchain.ToolchainManager;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
 /**
  * Run tests using Surefire.
  *
@@ -832,12 +833,20 @@ public class SurefirePlugin
         {
             return null;
         }
-        int index = test.indexOf( '#' );
-        if ( index >= 0 )
+        String[] testArray = StringUtils.split( test, "," );
+        StringBuffer tests = new StringBuffer();
+        for ( int i = 0; i < testArray.length; i++ )
         {
-            return test.substring( 0, index );
+            String singleTest = testArray[i];
+            int index = singleTest.indexOf( '#' );
+            if ( index >= 0 )
+            {// the way version 2.7.3.  support single test method
+                singleTest = singleTest.substring( 0, index );
+            }
+            tests.append( singleTest );
+            tests.append( "," );
         }
-        return test;
+        return tests.toString();
     }
 
     /**
@@ -849,10 +858,27 @@ public class SurefirePlugin
         {
             return null;
         }
+        //modified by rainLee, see http://jira.codehaus.org/browse/SUREFIRE-745
         int index = this.test.indexOf( '#' );
+        int index2 = this.test.indexOf( "," );
         if ( index >= 0 )
         {
-            return this.test.substring( index + 1, this.test.length() );
+            if ( index2 < 0 )
+            {
+                String testStrAfterFirstSharp = this.test.substring( index + 
1, this.test.length() );
+                if ( testStrAfterFirstSharp.indexOf( "+" ) < 0 )
+                {//the original way
+                    return testStrAfterFirstSharp;
+                }
+                else
+                {
+                    return this.test;
+                }
+            }
+            else
+            {
+                return this.test;
+            }
         }
         return null;
     }

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMultipleMethodsIT.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMultipleMethodsIT.java?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMultipleMethodsIT.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMultipleMethodsIT.java
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,50 @@
+package org.apache.maven.surefire.its;
+
+import org.apache.maven.surefire.its.fixture.SurefireIntegrationTestCase;
+/*
+ * 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.
+ */
+
+
+/**
+ * Test project using -Dtest=mtClass#myMethod+myMethod2,secondClass#testMethod
+ *
+ * @author <a href="mailto:ytso...@gmail.com";>rainLee</a>
+ */
+public class TestMultipleMethodsIT
+    extends SurefireIntegrationTestCase
+{
+    public void multipleMethod( String projectName )
+        throws Exception
+    {
+        unpack( projectName 
).executeTest().verifyErrorFreeLog().assertTestSuiteResults( 3, 0, 0, 0 );
+    }
+
+    public void testJunit44()
+        throws Exception
+    {
+        multipleMethod( "junit44-multiple-methods" );
+    }
+
+    public void testJunit48()
+        throws Exception
+    {
+        multipleMethod( "junit48-multiple-methods" );
+    }
+
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMultipleMethodsIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMultipleMethodsIT.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/pom.xml?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/pom.xml
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/pom.xml
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>junit4</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test for JUnit 4</name>
+
+
+  <properties>
+    <junitVersion>4.4</junitVersion>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junitVersion}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire.version}</version>
+        <configuration>
+          
<test>junit4.BasicTest#testSuccessOne+testFailOne,junit4.TestThree#testSuccessTwo</test>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/BasicTest.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/BasicTest.java?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/BasicTest.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/BasicTest.java
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,63 @@
+package junit4;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class BasicTest
+{
+
+    private boolean setUpCalled = false;
+
+    private static boolean tearDownCalled = false;
+    
+    @Before
+    public void setUp()
+    {
+        setUpCalled = true;
+        tearDownCalled = false;
+        System.out.println( "Called setUp" );
+    }
+
+    @After
+    public void tearDown()
+    {
+        setUpCalled = false;
+        tearDownCalled = true;
+        System.out.println( "Called tearDown" );
+    }
+
+    @Test
+    public void testSetUp()
+    {
+        Assert.assertTrue( "setUp was not called", setUpCalled );
+    }
+    
+    
+    @Test
+    public void testSuccessOne()
+    {
+        Assert.assertTrue( true );
+    }    
+    
+    @Test
+    public void testSuccessTwo()
+    {
+        Assert.assertTrue( true );
+    }   
+    
+    @Test
+    public void testFailOne()
+    {
+        Assert.assertFalse( false );
+    } 
+
+    @AfterClass
+    public static void oneTimeTearDown()
+    {
+        
+    }
+
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/BasicTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/BasicTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestThree.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestThree.java?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestThree.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestThree.java
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,57 @@
+package junit4;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class TestThree
+{
+
+    private boolean setUpCalled = false;
+
+    private static boolean tearDownCalled = false;
+    
+    @Before
+    public void setUp()
+    {
+        setUpCalled = true;
+        tearDownCalled = false;
+        System.out.println( "Called setUp" );
+    }
+
+    @After
+    public void tearDown()
+    {
+        setUpCalled = false;
+        tearDownCalled = true;
+        System.out.println( "Called tearDown" );
+    }
+
+    @Test
+    public void testSetUp()
+    {
+        Assert.assertTrue( "setUp was not called", setUpCalled );
+    }
+    
+    
+    @Test
+    public void testSuccessOne()
+    {
+        Assert.assertTrue( true );
+    } 
+    
+    @Test
+    public void testSuccessTwo()
+    {
+        Assert.assertTrue( true );
+    }    
+
+    @AfterClass
+    public static void oneTimeTearDown()
+    {
+        
+    }
+
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestThree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestThree.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestTwo.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestTwo.java?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestTwo.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestTwo.java
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,57 @@
+package junit4;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class TestTwo
+{
+
+    private boolean setUpCalled = false;
+
+    private static boolean tearDownCalled = false;
+    
+    @Before
+    public void setUp()
+    {
+        setUpCalled = true;
+        tearDownCalled = false;
+        System.out.println( "Called setUp" );
+    }
+
+    @After
+    public void tearDown()
+    {
+        setUpCalled = false;
+        tearDownCalled = true;
+        System.out.println( "Called tearDown" );
+    }
+
+    @Test
+    public void testSetUp()
+    {
+        Assert.assertTrue( "setUp was not called", setUpCalled );
+    }
+    
+    
+    @Test
+    public void testSuccessOne()
+    {
+        Assert.assertTrue( true );
+    } 
+    
+    @Test
+    public void testSuccessTwo()
+    {
+        Assert.assertTrue( true );
+    }    
+
+    @AfterClass
+    public static void oneTimeTearDown()
+    {
+        
+    }
+
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestTwo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit44-multiple-methods/src/test/java/junit4/TestTwo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/pom.xml?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/pom.xml
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/pom.xml
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>junit4</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test for JUnit 4.8.1</name>
+
+
+  <properties>
+    <junitVersion>4.8.1</junitVersion>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junitVersion}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire.version}</version>
+        <configuration>
+          
<test>junit4.BasicTest#testSuccessOne+testFailOne,junit4.TestThree#testSuccessTwo</test>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/BasicTest.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/BasicTest.java?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/BasicTest.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/BasicTest.java
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,63 @@
+package junit4;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class BasicTest
+{
+
+    private boolean setUpCalled = false;
+
+    private static boolean tearDownCalled = false;
+    
+    @Before
+    public void setUp()
+    {
+        setUpCalled = true;
+        tearDownCalled = false;
+        System.out.println( "Called setUp" );
+    }
+
+    @After
+    public void tearDown()
+    {
+        setUpCalled = false;
+        tearDownCalled = true;
+        System.out.println( "Called tearDown" );
+    }
+
+    @Test
+    public void testSetUp()
+    {
+        Assert.assertTrue( "setUp was not called", setUpCalled );
+    }
+    
+    
+    @Test
+    public void testSuccessOne()
+    {
+        Assert.assertTrue( true );
+    }    
+    
+    @Test
+    public void testSuccessTwo()
+    {
+        Assert.assertTrue( true );
+    }   
+    
+    @Test
+    public void testFailOne()
+    {
+        Assert.assertFalse( false );
+    } 
+
+    @AfterClass
+    public static void oneTimeTearDown()
+    {
+        
+    }
+
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/BasicTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/BasicTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestThree.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestThree.java?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestThree.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestThree.java
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,57 @@
+package junit4;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class TestThree
+{
+
+    private boolean setUpCalled = false;
+
+    private static boolean tearDownCalled = false;
+    
+    @Before
+    public void setUp()
+    {
+        setUpCalled = true;
+        tearDownCalled = false;
+        System.out.println( "Called setUp" );
+    }
+
+    @After
+    public void tearDown()
+    {
+        setUpCalled = false;
+        tearDownCalled = true;
+        System.out.println( "Called tearDown" );
+    }
+
+    @Test
+    public void testSetUp()
+    {
+        Assert.assertTrue( "setUp was not called", setUpCalled );
+    }
+    
+    
+    @Test
+    public void testSuccessOne()
+    {
+        Assert.assertTrue( true );
+    } 
+    
+    @Test
+    public void testSuccessTwo()
+    {
+        Assert.assertTrue( true );
+    }    
+
+    @AfterClass
+    public static void oneTimeTearDown()
+    {
+        
+    }
+
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestThree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestThree.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestTwo.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestTwo.java?rev=1294568&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestTwo.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestTwo.java
 Tue Feb 28 10:46:43 2012
@@ -0,0 +1,57 @@
+package junit4;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class TestTwo
+{
+
+    private boolean setUpCalled = false;
+
+    private static boolean tearDownCalled = false;
+    
+    @Before
+    public void setUp()
+    {
+        setUpCalled = true;
+        tearDownCalled = false;
+        System.out.println( "Called setUp" );
+    }
+
+    @After
+    public void tearDown()
+    {
+        setUpCalled = false;
+        tearDownCalled = true;
+        System.out.println( "Called tearDown" );
+    }
+
+    @Test
+    public void testSetUp()
+    {
+        Assert.assertTrue( "setUp was not called", setUpCalled );
+    }
+    
+    
+    @Test
+    public void testSuccessOne()
+    {
+        Assert.assertTrue( true );
+    } 
+    
+    @Test
+    public void testSuccessTwo()
+    {
+        Assert.assertTrue( true );
+    }    
+
+    @AfterClass
+    public static void oneTimeTearDown()
+    {
+        
+    }
+
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestTwo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-multiple-methods/src/test/java/junit4/TestTwo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java?rev=1294568&r1=1294567&r2=1294568&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
 (original)
+++ 
maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
 Tue Feb 28 10:46:43 2012
@@ -19,9 +19,6 @@ package org.apache.maven.surefire.junit4
  * under the License.
  */
 
-import java.lang.reflect.Method;
-import java.util.Iterator;
-import java.util.List;
 import org.apache.maven.surefire.common.junit4.JUnit4RunListener;
 import org.apache.maven.surefire.common.junit4.JUnit4RunListenerFactory;
 import org.apache.maven.surefire.common.junit4.JUnit4TestChecker;
@@ -43,12 +40,15 @@ import org.apache.maven.surefire.util.Ru
 import org.apache.maven.surefire.util.TestsToRun;
 import org.apache.maven.surefire.util.internal.StringUtils;
 import org.codehaus.plexus.util.SelectorUtils;
-
 import org.junit.runner.Request;
 import org.junit.runner.Result;
 import org.junit.runner.Runner;
 import org.junit.runner.notification.RunNotifier;
 
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * @author Kristian Rosenvold
  */
@@ -131,7 +131,16 @@ public class JUnit4Provider
 
         try
         {
-            execute( clazz, listeners, this.requestedTestMethod );
+            if ( !StringUtils.isBlank( this.requestedTestMethod ) )
+            {
+                String actualTestMethod = getMethod( clazz, 
this.requestedTestMethod );//add by rainLee
+                String[] testMethods = StringUtils.split( actualTestMethod, 
"+" );
+                execute( clazz, listeners, testMethods );
+            }
+            else
+            {//the original way
+                execute( clazz, listeners, null );
+            }
         }
         catch ( TestSetFailedException e )
         {
@@ -214,18 +223,22 @@ public class JUnit4Provider
     }
 
 
-    private static void execute( Class<?> testClass, RunNotifier fNotifier, 
String testMethod )
+    private static void execute( Class<?> testClass, RunNotifier fNotifier, 
String[] testMethods )
         throws TestSetFailedException
     {
-        if ( !StringUtils.isBlank( testMethod ) )
+        if ( null != testMethods )
         {
             Method[] methods = testClass.getMethods();
             for ( int i = 0, size = methods.length; i < size; i++ )
             {
-                if ( SelectorUtils.match( testMethod, methods[i].getName() ) )
+                for ( int j = 0; j < testMethods.length; j++ )
                 {
-                    Runner junitTestRunner = Request.method( testClass, 
methods[i].getName() ).getRunner();
-                    junitTestRunner.run( fNotifier );
+                    if ( SelectorUtils.match( testMethods[j], 
methods[i].getName() ) )
+                    {
+                        Runner junitTestRunner = Request.method( testClass, 
methods[i].getName() ).getRunner();
+                        junitTestRunner.run( fNotifier );
+                    }
+
                 }
             }
             return;
@@ -235,4 +248,36 @@ public class JUnit4Provider
 
         junitTestRunner.run( fNotifier );
     }
+
+    /**
+     * this method retrive  testMethods from String like 
"com.xx.ImmutablePairTest#testBasic,com.xx.StopWatchTest#testLang315+testStopWatchSimpleGet"
+     * <br>
+     * and we need to think about cases that 2 or more method in 1 class. we 
should choose the correct method
+     *
+     * @param testClass
+     * @param testMethodStr
+     * @return
+     * @author railLee
+     */
+    private static String getMethod( Class testClass, String testMethodStr )
+    {
+        String className = testClass.getName();
+
+        if ( testMethodStr.indexOf( "#" ) < 0 && testMethodStr.indexOf( "," ) 
< 0 )
+        {//the original way
+            return testMethodStr;
+        }
+        testMethodStr += ",";//for the bellow  split code
+        int beginIndex = testMethodStr.indexOf( className );
+        int endIndex = testMethodStr.indexOf( ",", beginIndex );
+        String classMethodStr =
+            testMethodStr.substring( beginIndex, endIndex );//String like 
"StopWatchTest#testLang315"
+
+        int index = classMethodStr.indexOf( '#' );
+        if ( index >= 0 )
+        {
+            return classMethodStr.substring( index + 1, 
classMethodStr.length() );
+        }
+        return null;
+    }
 }


Reply via email to