Return-Path: X-Original-To: apmail-maven-commits-archive@www.apache.org Delivered-To: apmail-maven-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ACA8518496 for ; Fri, 23 Oct 2015 20:32:12 +0000 (UTC) Received: (qmail 58193 invoked by uid 500); 23 Oct 2015 20:32:12 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 58140 invoked by uid 500); 23 Oct 2015 20:32:12 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 58131 invoked by uid 99); 23 Oct 2015 20:32:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Oct 2015 20:32:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 525F2E027F; Fri, 23 Oct 2015 20:32:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tibordigana@apache.org To: commits@maven.apache.org Message-Id: <2238705b2e704cf885d6f25e7b58d8da@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: maven-surefire git commit: [SUREFIRE-1187] JUnit4 Provider created unnecessary Runner instance Date: Fri, 23 Oct 2015 20:32:12 +0000 (UTC) Repository: maven-surefire Updated Branches: refs/heads/master ffadd7e72 -> d4135dd77 [SUREFIRE-1187] JUnit4 Provider created unnecessary Runner instance Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/d4135dd7 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/d4135dd7 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/d4135dd7 Branch: refs/heads/master Commit: d4135dd7734428f879eed771ca60b7081c75acc5 Parents: ffadd7e Author: tibordigana Authored: Fri Oct 23 22:31:12 2015 +0200 Committer: tibordigana Committed: Fri Oct 23 22:31:12 2015 +0200 ---------------------------------------------------------------------- .../maven/surefire/junit4/JUnit4Provider.java | 15 ++++++------ .../surefire/junit4/JUnit4ProviderTest.java | 25 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4135dd7/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java index aae5fe3..493369d 100644 --- a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java +++ b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java @@ -19,7 +19,6 @@ package org.apache.maven.surefire.junit4; * under the License. */ -import java.util.ArrayList; import java.util.Collection; import java.util.Set; @@ -52,7 +51,6 @@ import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; import org.junit.runner.notification.StoppedByUserException; -import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.createSuiteDescription; import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.cutTestClassAndMethod; import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.generateFailingTests; import static org.apache.maven.surefire.common.junit4.JUnit4Reflector.createDescription; @@ -164,7 +162,7 @@ public class JUnit4Provider try { notifier.fireTestRunStarted( testsToRun.allowEagerReading() - ? createTestsDescription() + ? createTestsDescription( testsToRun ) : createDescription( UNDETERMINED_TESTS_DESCRIPTION ) ); if ( commandsReader != null ) @@ -318,14 +316,15 @@ public class JUnit4Provider } } - private Description createTestsDescription() + static Description createTestsDescription( Iterable> classes ) { - Collection> classes = new ArrayList>(); - for ( Class clazz : testsToRun ) + // "null" string rather than null; otherwise NPE in junit:4.0 + Description description = createDescription( "null" ); + for ( Class clazz : classes ) { - classes.add( clazz ); + description.addChild( createDescription( clazz.getName() ) ); } - return createSuiteDescription( classes ); + return description; } private static boolean isJUnit4UpgradeCheck() http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4135dd7/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java b/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java index 8f0356c..586c55e 100644 --- a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java +++ b/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java @@ -22,9 +22,15 @@ package org.apache.maven.surefire.junit4; import junit.framework.TestCase; import org.apache.maven.surefire.booter.BaseProviderFactory; import org.apache.maven.surefire.testset.TestRequest; +import org.junit.runner.Description; +import java.util.Arrays; import java.util.HashMap; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.runner.Description.createSuiteDescription; + /** * @author Kristian Rosenvold */ @@ -44,4 +50,23 @@ public class JUnit4ProviderTest providerParameters.setTestRequest( new TestRequest( null, null, null ) ); return new JUnit4Provider( providerParameters ); } + + public void testShouldCreateDescription() + { + class A { + } + + class B { + } + + Description d = JUnit4Provider.createTestsDescription( Arrays.>asList( A.class, B.class ) ); + assertThat( d, is( notNullValue() ) ); + assertThat( d.getDisplayName(), not( isEmptyOrNullString() ) ); + assertThat( d.getDisplayName(), is( "null" ) ); + assertThat( d.getChildren(), hasSize( 2 ) ); + Description a = createSuiteDescription( A.class ); + Description b = createSuiteDescription( B.class ); + assertThat( d.getChildren(), contains( a, b ) ); + } + }