You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/07/03 19:54:35 UTC
svn commit: r1356850 - in
/maven/surefire/trunk/surefire-providers/surefire-junit47/src:
main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java
test/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListenerTest.java
Author: olamy
Date: Tue Jul 3 17:54:34 2012
New Revision: 1356850
URL: http://svn.apache.org/viewvc?rev=1356850&view=rev
Log:
[SUREFIRE-876] surefire-junit47 does not work in an OSGi classloader environment
Submitted by Jan Sievers.
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListenerTest.java
Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java?rev=1356850&r1=1356849&r2=1356850&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java Tue Jul 3 17:54:34 2012
@@ -66,15 +66,15 @@ public class JUnitCoreRunListener
final ArrayList<Description> children = description.getChildren();
TestSet testSet = new TestSet( description );
- Class<?> itemTestClass = null;
+ String itemTestClassName = null;
for ( Description item : children )
{
if ( item.isTest() && item.getMethodName() != null )
{
testSet.incrementTestMethodCount();
- if ( itemTestClass == null )
+ if ( itemTestClassName == null )
{
- itemTestClass = item.getTestClass();
+ itemTestClassName = item.getClassName();
}
}
else if ( item.getChildren().size() > 0 )
@@ -86,9 +86,9 @@ public class JUnitCoreRunListener
classMethodCounts.put( item.getClassName(), testSet );
}
}
- if ( itemTestClass != null )
+ if ( itemTestClassName != null )
{
- classMethodCounts.put( itemTestClass.getName(), testSet );
+ classMethodCounts.put( itemTestClassName, testSet );
}
}
Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListenerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListenerTest.java?rev=1356850&r1=1356849&r2=1356850&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListenerTest.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListenerTest.java Tue Jul 3 17:54:34 2012
@@ -20,12 +20,15 @@ package org.apache.maven.surefire.junitc
*/
import java.util.HashMap;
+import java.util.Map;
+
import org.apache.maven.surefire.junit4.MockReporter;
import junit.framework.TestCase;
import org.junit.Assume;
import org.junit.Test;
import org.junit.runner.Computer;
+import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;
@@ -60,6 +63,25 @@ public class JUnitCoreRunListenerTest
assertEquals( 1, result.getRunCount() );
}
+ public void testTestClassNotLoadableFromJUnitClassLoader()
+ throws Exception
+ {
+ // can't use Description.createTestDescription() methods as these require a loaded Class
+ Description testDescription = Description.createSuiteDescription( "testMethod(cannot.be.loaded.by.junit.Test)" );
+ assertEquals( "testMethod", testDescription.getMethodName() );
+ assertEquals( "cannot.be.loaded.by.junit.Test", testDescription.getClassName() );
+ // assert that the test class is not visible by the JUnit classloader
+ assertNull( testDescription.getTestClass() );
+ Description suiteDescription = Description.createSuiteDescription( "testSuite" );
+ suiteDescription.addChild( testDescription );
+ Map<String, TestSet> classMethodCounts = new HashMap<String, TestSet>();
+ JUnitCoreRunListener listener = new JUnitCoreRunListener( new MockReporter(), classMethodCounts );
+ listener.testRunStarted( suiteDescription );
+ assertEquals( 1, classMethodCounts.size() );
+ TestSet testSet = classMethodCounts.get( "cannot.be.loaded.by.junit.Test" );
+ assertNotNull( testSet );
+ }
+
public static class STest1
{
@Test