This is an automated email from the ASF dual-hosted git repository.
olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new 69227a2e0 Fix #2808: pick a JUnit 4 parameterized test run by its
index again (#3606)
69227a2e0 is described below
commit 69227a2e093fa04c254463c43b14ca11af72f99a
Author: Olivier Lamy <[email protected]>
AuthorDate: Thu Nov 19 19:36:30 2026 +1000
Fix #2808: pick a JUnit 4 parameterized test run by its index again (#3606)
Signed-off-by: Olivier Lamy <[email protected]>
---
.../src/site/markdown/examples/single-test.md.vm | 2 +-
.../surefire/api/testset/TestListResolver.java | 58 ++++++++++-----
.../surefire/api/testset/TestListResolverTest.java | 47 ++++++++++++
.../Surefire2808ParameterizedIndexSelectionIT.java | 87 ++++++++++++++++++++++
.../pom.xml | 80 ++++++++++++++++++++
.../src/test/java/pkg/IndexedTest.java | 51 +++++++++++++
.../src/test/java/pkg/NamedIndexTest.java | 52 +++++++++++++
.../surefire/junitplatform/TestMethodFilter.java | 18 ++++-
.../junitplatform/TestMethodFilterTest.java | 53 +++++++++++++
9 files changed, 425 insertions(+), 23 deletions(-)
diff --git a/maven-surefire-plugin/src/site/markdown/examples/single-test.md.vm
b/maven-surefire-plugin/src/site/markdown/examples/single-test.md.vm
index 9d49b3740..ff3f08f8c 100644
--- a/maven-surefire-plugin/src/site/markdown/examples/single-test.md.vm
+++ b/maven-surefire-plugin/src/site/markdown/examples/single-test.md.vm
@@ -125,7 +125,7 @@ mvn "-Dit.test=Basic*, !%regex[.*.Unstable.*],
!%regex[.*.MyIT.class#one.*|two.*
#{end}
```
-The exclamation mark (\!) excludes tests. The character (?) within non-regex
pattern replaces one character in file name or path. The file extensions are
not mandatory in non-regex patterns, and packages with slash can be used. The
regex validates fully qualified class file, and validates test methods
separately after (#) however class is optional. The regex supports '.class'
file extension only. Note the regex comments, marked by (#) character, are
unsupported. The Parameterized JUnit r [...]
+The exclamation mark (\!) excludes tests. The character (?) within non-regex
pattern replaces one character in file name or path. The file extensions are
not mandatory in non-regex patterns, and packages with slash can be used. The
regex validates fully qualified class file, and validates test methods
separately after (#) however class is optional. The regex supports '.class'
file extension only. Note the regex comments, marked by (#) character, are
unsupported. The Parameterized JUnit r [...]
Fully qualified class name
--------------------------
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/TestListResolver.java
b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/TestListResolver.java
index 262582f62..eab95b43d 100644
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/TestListResolver.java
+++
b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/TestListResolver.java
@@ -172,30 +172,50 @@ public boolean shouldRun(Class<?> testClass, String
methodName) {
public boolean shouldRun(String testClassFile, String methodName) {
if (isEmpty() || isBlank(testClassFile) && isBlank(methodName)) {
return true;
- } else {
- boolean shouldRun = false;
+ }
+ return isIncluded(testClassFile, methodName) &&
!isExcluded(testClassFile, methodName);
+ }
- if (getIncludedPatterns().isEmpty()) {
- shouldRun = true;
- } else {
- for (ResolvedTest filter : getIncludedPatterns()) {
- if (filter.matchAsInclusive(testClassFile, methodName)) {
- shouldRun = true;
- break;
- }
- }
+ /**
+ * Same as {@link #shouldRun(String, String)} for a test that goes by two
method names.
+ * A JUnit 4 parameterized test, for example, is both {@code test} and
{@code test[1]}.
+ * The test runs when an include matches one of the names and no exclude
matches either of them.
+ *
+ * @param testClassFile format must be e.g. "my/package/MyTest.class"
including class extension
+ * @param methodName real test-method name, e.g. {@code test}
+ * @param otherMethodName the other name of the same test, e.g. {@code
test[1]}
+ * @return {@code true} if the test should run
+ * @since 3.6.2
+ */
+ public boolean shouldRun(String testClassFile, String methodName, String
otherMethodName) {
+ if (isEmpty()) {
+ return true;
+ }
+ if (isExcluded(testClassFile, methodName) || isExcluded(testClassFile,
otherMethodName)) {
+ return false;
+ }
+ return isIncluded(testClassFile, methodName) ||
isIncluded(testClassFile, otherMethodName);
+ }
+
+ private boolean isIncluded(String testClassFile, String methodName) {
+ if (getIncludedPatterns().isEmpty()) {
+ return true;
+ }
+ for (ResolvedTest filter : getIncludedPatterns()) {
+ if (filter.matchAsInclusive(testClassFile, methodName)) {
+ return true;
}
+ }
+ return false;
+ }
- if (shouldRun) {
- for (ResolvedTest filter : getExcludedPatterns()) {
- if (filter.matchAsExclusive(testClassFile, methodName)) {
- shouldRun = false;
- break;
- }
- }
+ private boolean isExcluded(String testClassFile, String methodName) {
+ for (ResolvedTest filter : getExcludedPatterns()) {
+ if (filter.matchAsExclusive(testClassFile, methodName)) {
+ return true;
}
- return shouldRun;
}
+ return false;
}
@Override
diff --git
a/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/TestListResolverTest.java
b/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/TestListResolverTest.java
index 9fb2b9301..a174739ce 100644
---
a/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/TestListResolverTest.java
+++
b/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/TestListResolverTest.java
@@ -413,6 +413,53 @@ public void testRegexRuleViolationInvalidMethodPattern() {
assertThrows(IllegalArgumentException.class, () -> new
TestListResolver("%regex[#.(.]"));
}
+ @Test
+ public void testIndexOfParameterizedTest() {
+ TestListResolver resolver = new TestListResolver("MyTest#test[1]");
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "test", "test[1]"));
+ assertFalse(resolver.shouldRun("pkg/MyTest.class", "test", "test[0]"));
+ assertFalse(resolver.shouldRun("pkg/MyTest.class", "test",
"test[10]"));
+ assertFalse(resolver.shouldRun("pkg/MyTest.class", "anotherTest",
"anotherTest[1]"));
+ }
+
+ @Test
+ public void testAnyIndexOfParameterizedTest() {
+ TestListResolver resolver = new TestListResolver("MyTest#test[*]");
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "test", "test[0]"));
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "test", "test[1]"));
+ assertFalse(resolver.shouldRun("pkg/MyTest.class", "anotherTest",
"anotherTest[1]"));
+ }
+
+ @Test
+ public void testIndexOfParameterizedTestWithCustomName() {
+ TestListResolver resolver = new TestListResolver("MyTest#test[5:*]");
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "test", "test[5:
fib(5)=5]"));
+ assertFalse(resolver.shouldRun("pkg/MyTest.class", "test", "test[6:
fib(6)=8]"));
+ }
+
+ @Test
+ public void testMethodNameSelectsEveryIndexOfParameterizedTest() {
+ TestListResolver resolver = new TestListResolver("MyTest#test");
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "test", "test[0]"));
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "test", "test[1]"));
+ }
+
+ @Test
+ public void testExcludedIndexOfParameterizedTest() {
+ TestListResolver resolver = new TestListResolver("MyTest,
!MyTest#test[1]");
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "test", "test[0]"));
+ assertFalse(resolver.shouldRun("pkg/MyTest.class", "test", "test[1]"));
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "anotherTest",
"anotherTest[1]"));
+ }
+
+ @Test
+ public void testExcludedMethodNameExcludesEveryIndexOfParameterizedTest() {
+ TestListResolver resolver = new TestListResolver("!MyTest#test");
+ assertFalse(resolver.shouldRun("pkg/MyTest.class", "test", "test[0]"));
+ assertFalse(resolver.shouldRun("pkg/MyTest.class", "test", "test[1]"));
+ assertTrue(resolver.shouldRun("pkg/MyTest.class", "anotherTest",
"anotherTest[1]"));
+ }
+
private static Set<ResolvedTest> resolveClass(String patterns) {
Set<ResolvedTest> resolved = new HashSet<>();
for (String pattern : patterns.split(",")) {
diff --git
a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire2808ParameterizedIndexSelectionIT.java
b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire2808ParameterizedIndexSelectionIT.java
new file mode 100644
index 000000000..40b6e13b4
--- /dev/null
+++
b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire2808ParameterizedIndexSelectionIT.java
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+package org.apache.maven.surefire.its.jiras;
+
+import org.apache.maven.surefire.its.fixture.OutputValidator;
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Picks runs of a JUnit 4 parameterized test by their index, e.g. {@code
-Dtest=IndexedTest#test[1]}.
+ * This worked with the old JUnit 4 provider and stopped working once JUnit 4
tests ran on the Vintage engine.
+ *
+ * @see <a href="https://github.com/apache/maven-surefire/issues/2808">GitHub
issue #2808</a>
+ */
+public class Surefire2808ParameterizedIndexSelectionIT extends
SurefireJUnit4IntegrationTestCase {
+
+ private static final String PROJECT =
"surefire-2808-parameterized-index-selection";
+
+ @Test
+ void oneRunByIndex() throws Exception {
+ OutputValidator validator = unpack(PROJECT)
+ .setTestToRun("IndexedTest#test[1]")
+ .executeTest()
+ .verifyErrorFree(1);
+ validator.verifyTextInLog("IndexedTest.test value=1");
+ validator.verifyTextNotInLog("IndexedTest.test value=0");
+ validator.verifyTextNotInLog("IndexedTest.anotherTest");
+ }
+
+ @Test
+ void allRunsWithWildcardIndex() throws Exception {
+ OutputValidator validator = unpack(PROJECT)
+ .setTestToRun("IndexedTest#test[*]")
+ .executeTest()
+ .verifyErrorFree(3);
+ validator.verifyTextNotInLog("IndexedTest.anotherTest");
+ }
+
+ @Test
+ void allRunsByMethodName() {
+
unpack(PROJECT).setTestToRun("IndexedTest#test").executeTest().verifyErrorFree(3);
+ }
+
+ @Test
+ void oneRunWithCustomName() throws Exception {
+ OutputValidator validator = unpack(PROJECT)
+ .setTestToRun("NamedIndexTest#square[2:*]")
+ .executeTest()
+ .verifyErrorFree(1);
+ validator.verifyTextInLog("NamedIndexTest.square input=3");
+ }
+
+ @Test
+ void excludeOneRun() throws Exception {
+ OutputValidator validator = unpack(PROJECT)
+ .setTestToRun("IndexedTest, !IndexedTest#test[1]")
+ .executeTest()
+ .verifyErrorFree(5);
+ validator.verifyTextNotInLog("IndexedTest.test value=1");
+ }
+
+ @Test
+ void oneRunByIndexWithJupiterOnClasspath() throws Exception {
+ OutputValidator validator = unpack(PROJECT)
+ .activateProfile("jupiter")
+ .setTestToRun("IndexedTest#test[1]")
+ .executeTest()
+ .verifyErrorFree(1);
+ validator.verifyTextInLog("IndexedTest.test value=1");
+ }
+}
diff --git
a/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/pom.xml
b/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/pom.xml
new file mode 100644
index 000000000..b0531ec2a
--- /dev/null
+++
b/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/pom.xml
@@ -0,0 +1,80 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.surefire</groupId>
+ <artifactId>surefire-2808-parameterized-index-selection</artifactId>
+ <version>1.0</version>
+ <name>Select one run of a JUnit 4 parameterized test</name>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <junit5.version>5.14.4</junit5.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.13.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <!-- JUnit 4 tests next to Jupiter, like in the original report -->
+ <id>jupiter</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <version>${junit5.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <version>${junit5.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire.version}</version>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/src/test/java/pkg/IndexedTest.java
b/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/src/test/java/pkg/IndexedTest.java
new file mode 100644
index 000000000..8e4086838
--- /dev/null
+++
b/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/src/test/java/pkg/IndexedTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+package pkg;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class IndexedTest {
+ @Parameters
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {{0}, {1}, {2}});
+ }
+
+ private final int value;
+
+ public IndexedTest(int value) {
+ this.value = value;
+ }
+
+ @Test
+ public void test() {
+ System.out.println("IndexedTest.test value=" + value);
+ }
+
+ @Test
+ public void anotherTest() {
+ System.out.println("IndexedTest.anotherTest value=" + value);
+ }
+}
diff --git
a/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/src/test/java/pkg/NamedIndexTest.java
b/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/src/test/java/pkg/NamedIndexTest.java
new file mode 100644
index 000000000..11f580135
--- /dev/null
+++
b/surefire-its/src/test/resources/surefire-2808-parameterized-index-selection/src/test/java/pkg/NamedIndexTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+package pkg;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Parameterized.class)
+public class NamedIndexTest {
+ @Parameters(name = "{index}: square({0})={1}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {{1, 1}, {2, 4}, {3, 9}});
+ }
+
+ private final int input;
+
+ private final int expected;
+
+ public NamedIndexTest(int input, int expected) {
+ this.input = input;
+ this.expected = expected;
+ }
+
+ @Test
+ public void square() {
+ System.out.println("NamedIndexTest.square input=" + input);
+ assertEquals(expected, input * input);
+ }
+}
diff --git
a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestMethodFilter.java
b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestMethodFilter.java
index a3ca92e66..4d083ce33 100644
---
a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestMethodFilter.java
+++
b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestMethodFilter.java
@@ -41,15 +41,27 @@ public FilterResult apply(TestDescriptor descriptor) {
.getSource()
.filter(MethodSource.class::isInstance)
.map(MethodSource.class::cast)
- .map(this::shouldRun)
+ .map(source -> shouldRun(source,
descriptor.getLegacyReportingName()))
.orElse(true);
return FilterResult.includedIf(shouldRun);
}
- private boolean shouldRun(MethodSource source) {
+ private boolean shouldRun(MethodSource source, String reportingName) {
String testClass =
TestListResolver.toClassFileName(source.getClassName());
String testMethod = source.getMethodName();
- return this.testListResolver.shouldRun(testClass, testMethod);
+ if (isIndexedName(testMethod, reportingName)) {
+ return testListResolver.shouldRun(testClass, testMethod,
reportingName);
+ }
+ return testListResolver.shouldRun(testClass, testMethod);
+ }
+
+ /**
+ * A JUnit 4 parameterized test run by the Vintage engine is reported as
{@code test[1]}, or with the name
+ * given in {@code @Parameters}, while its method source only says {@code
test}. Matching both names lets
+ * {@code -Dtest=MyTest#test[1]} pick one run, and {@code
-Dtest=MyTest#test} still picks all of them.
+ */
+ private static boolean isIndexedName(String methodName, String
reportingName) {
+ return reportingName != null && reportingName.startsWith(methodName +
'[') && reportingName.endsWith("]");
}
}
diff --git
a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java
b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java
index 3892ae840..cebd9add9 100644
---
a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java
+++
b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java
@@ -20,6 +20,7 @@
import java.lang.reflect.Method;
import java.util.Collections;
+import java.util.Optional;
import org.apache.maven.surefire.api.testset.TestListResolver;
import org.junit.jupiter.api.Test;
@@ -28,8 +29,11 @@
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
import org.junit.platform.engine.ConfigurationParameters;
import org.junit.platform.engine.FilterResult;
+import org.junit.platform.engine.TestDescriptor;
+import org.junit.platform.engine.TestSource;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.reporting.OutputDirectoryProvider;
+import org.junit.platform.engine.support.descriptor.MethodSource;
import static
org.apache.maven.surefire.api.testset.TestListResolver.toClassFileName;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -80,6 +84,55 @@ public void includesTestDescriptorWithClassSource() {
assertFalse(result.excluded());
}
+ @Test
+ public void includesOneRunOfJUnit4ParameterizedTest() {
+ TestMethodFilter indexFilter = new TestMethodFilter(new
TestListResolver("*TestClass#testMethod[1]"));
+
+
assertTrue(indexFilter.apply(newVintageDescriptor("testMethod[1]")).included());
+
assertTrue(indexFilter.apply(newVintageDescriptor("testMethod[0]")).excluded());
+
assertTrue(indexFilter.apply(newVintageDescriptor("testMethod[10]")).excluded());
+ }
+
+ @Test
+ public void includesOneRunOfJUnit4ParameterizedTestWithCustomName() {
+ TestMethodFilter indexFilter = new TestMethodFilter(new
TestListResolver("*TestClass#testMethod[2:*]"));
+
+ assertTrue(indexFilter
+ .apply(newVintageDescriptor("testMethod[2: fib(2)=1]"))
+ .included());
+ assertTrue(indexFilter
+ .apply(newVintageDescriptor("testMethod[3: fib(3)=2]"))
+ .excluded());
+ }
+
+ @Test
+ public void includesEveryRunOfJUnit4ParameterizedTestByMethodName() {
+ TestMethodFilter nameFilter = new TestMethodFilter(new
TestListResolver("*TestClass#testMethod"));
+
+
assertTrue(nameFilter.apply(newVintageDescriptor("testMethod[0]")).included());
+
assertTrue(nameFilter.apply(newVintageDescriptor("testMethod[1]")).included());
+ }
+
+ @Test
+ public void excludesOneRunOfJUnit4ParameterizedTest() {
+ TestMethodFilter excludeFilter = new TestMethodFilter(new
TestListResolver("!*TestClass#testMethod[1]"));
+
+
assertTrue(excludeFilter.apply(newVintageDescriptor("testMethod[0]")).included());
+
assertTrue(excludeFilter.apply(newVintageDescriptor("testMethod[1]")).excluded());
+ }
+
+ /**
+ * Mimics a JUnit 4 parameterized test run on the Vintage engine: the
method source has the plain
+ * method name, the reporting name has the index.
+ */
+ private static TestDescriptor newVintageDescriptor(String reportingName) {
+ TestDescriptor descriptor = mock(TestDescriptor.class);
+ when(descriptor.getSource())
+
.thenReturn(Optional.<TestSource>of(MethodSource.from(TestClass.class.getName(),
"testMethod")));
+ when(descriptor.getLegacyReportingName()).thenReturn(reportingName);
+ return descriptor;
+ }
+
private static TestMethodTestDescriptor newTestMethodDescriptor() throws
Exception {
UniqueId uniqueId = UniqueId.forEngine("method");
Class<TestClass> testClass = TestClass.class;