Author: krosenvold
Date: Mon Aug 22 19:47:12 2011
New Revision: 1160400

URL: http://svn.apache.org/viewvc?rev=1160400&view=rev
Log:
[SUREFIRE-761] java.lang.NoSuchMethodException when trying to run Junit 3 suite 
class

Patch and testcase submitted by Jab Sievers, applied with slight modifications 
to testcase

Added:
    maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/
    maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/
    maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/
    
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/
    
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/
    
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/
    
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/
    
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java
   (with props)
Modified:
    
maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java

Modified: 
maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java?rev=1160400&r1=1160399&r2=1160400&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
 (original)
+++ 
maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
 Mon Aug 22 19:47:12 2011
@@ -19,20 +19,17 @@ package org.apache.maven.surefire.junit;
  * under the License.
  */
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-import junit.framework.TestSuite;
 import org.apache.maven.surefire.common.junit3.JUnit3Reflector;
 import org.apache.maven.surefire.report.RunListener;
 import org.apache.maven.surefire.testset.TestSetFailedException;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
 public final class JUnitTestSet
     implements SurefireTestSet
 {
-    private final Method runMethod;
-
     private final Class testClass;
 
     private final JUnit3Reflector reflector;
@@ -61,15 +58,6 @@ public final class JUnitTestSet
 
         // The interface implemented by the dynamic proxy (TestListener), 
happens to be
         // the same as the param types of TestResult.addTestListener
-
-        if ( this.reflector.getTestInterface().isAssignableFrom( 
this.testClass ) )//testObject.getClass() ) )
-        {
-            runMethod = this.reflector.getTestInterfaceRunMethod();
-        }
-        else
-        {
-            runMethod = reflector.getRunMethod( this.testClass );
-        }
     }
 
 
@@ -81,6 +69,16 @@ public final class JUnitTestSet
         try
         {
             Object testObject = reflector.constructTestObject( testClass );
+            final Method runMethod;
+
+            if ( this.reflector.getTestInterface().isAssignableFrom( 
testObject.getClass() ) )
+            {
+                runMethod = this.reflector.getTestInterfaceRunMethod();
+            }
+            else
+            {
+                runMethod = reflector.getRunMethod( this.testClass );
+            }
 
             Object instanceOfTestResult = 
reflector.getTestResultClass().newInstance();
 

Added: 
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java?rev=1160400&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java
 (added)
+++ 
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java
 Mon Aug 22 19:47:12 2011
@@ -0,0 +1,119 @@
+package org.apache.maven.surefire.junit;
+
+/*
+ * 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.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.maven.surefire.common.junit3.JUnit3Reflector;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class JUnitTestSetTest
+    extends TestCase
+{
+
+    public void testExecuteSuiteClass()
+        throws TestSetFailedException
+    {
+        ClassLoader testClassLoader = this.getClass().getClassLoader();
+        JUnit3Reflector reflector = new JUnit3Reflector( testClassLoader );
+        JUnitTestSet testSet = new JUnitTestSet( Suite.class, reflector );
+        SuccessListener listener = new SuccessListener();
+        testSet.execute( listener, testClassLoader );
+        List succeededTests = listener.getSucceededTests();
+        assertEquals( 1, succeededTests.size() );
+        assertEquals( 
"testSuccess(org.apache.maven.surefire.junit.JUnitTestSetTest$AlwaysSucceeds)",
+                      ( (ReportEntry) succeededTests.get( 0 ) ).getName() );
+    }
+
+  public static final class AlwaysSucceeds
+      extends TestCase
+  {
+      public void testSuccess() {
+          assertTrue( true );
+      }
+  }
+
+  public static class SuccessListener
+      implements RunListener
+  {
+
+      private List succeededTests = new ArrayList();
+
+      public void testSetStarting( ReportEntry report )
+      {
+      }
+
+      public void testSetCompleted( ReportEntry report )
+      {
+      }
+
+      public void testStarting( ReportEntry report )
+      {
+      }
+
+      public void testSucceeded( ReportEntry report )
+      {
+          this.succeededTests.add( report );
+      }
+
+      public void testAssumptionFailure( ReportEntry report )
+      {
+          throw new IllegalStateException();
+      }
+
+      public void testError( ReportEntry report )
+      {
+          throw new IllegalStateException();
+      }
+
+      public void testFailed( ReportEntry report )
+      {
+          throw new IllegalStateException();
+      }
+
+      public void testSkipped( ReportEntry report )
+      {
+          throw new IllegalStateException();
+      }
+
+      public List getSucceededTests()
+      {
+          return succeededTests;
+      }
+
+  }
+
+  public static class Suite
+  {
+
+      public static Test suite()
+      {
+          TestSuite suite = new TestSuite();
+          suite.addTestSuite( AlwaysSucceeds.class );
+          return suite;
+      }
+  }
+}

Propchange: 
maven/surefire/trunk/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to