Skip to content

Commit 4f52c2d

Browse files
Fix for compilation on Java 8 and older Junit versions
1 parent 8aaf0a6 commit 4f52c2d

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

surefire-its/src/test/resources/junit5-testtemplate-bug/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
<version>${junit5.version}</version>
2323
<scope>test</scope>
2424
</dependency>
25+
<dependency>
26+
<groupId>org.junit.jupiter</groupId>
27+
<artifactId>junit-jupiter-api</artifactId>
28+
<version>${junit5.version}</version>
29+
<scope>test</scope>
30+
</dependency>
2531
<dependency>
2632
<groupId>org.junit.jupiter</groupId>
2733
<artifactId>junit-jupiter-params</artifactId>

surefire-its/src/test/resources/junit5-testtemplate-bug/src/test/java/pkg/FieldSettingTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
99
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
1010

11+
import java.util.Arrays;
1112
import java.util.List;
1213
import java.util.stream.Stream;
1314

@@ -44,7 +45,7 @@ private TestTemplateInvocationContext context(int parameter) {
4445
return new TestTemplateInvocationContext() {
4546
@Override
4647
public String getDisplayName(int invocationIndex) {
47-
return "[%d] %s".formatted(invocationIndex, parameter);
48+
return String.format("[%d] %s", invocationIndex, parameter);
4849
}
4950

5051
@Override
@@ -55,8 +56,8 @@ public List<Extension> getAdditionalExtensions() {
5556
}
5657

5758
private List<Extension> getBeforeEachCallbacks(int value) {
58-
return List.of(((BeforeEachCallback) ctx ->
59+
return Arrays.asList((BeforeEachCallback) ctx ->
5960
((FieldSettingTest) ctx.getRequiredTestInstance()).setTestValue(value)
60-
));
61+
);
6162
}
6263
}

surefire-its/src/test/resources/junit5-testtemplate-bug/src/test/java/pkg/ParamsContextTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ParamsContextTest {
1919

2020
@TestTemplate
2121
@ExtendWith(ParamsContextProvider.class)
22-
void testTemplatePartiallyFails(Integer value) {
22+
void testTemplatePartiallyFails(int value) {
2323
assertEquals(42, value);
2424
}
2525
}
@@ -40,15 +40,15 @@ private TestTemplateInvocationContext invocationContext(int parameter) {
4040
return new TestTemplateInvocationContext() {
4141
@Override
4242
public String getDisplayName(int invocationIndex) {
43-
return "[%d] %s".formatted(invocationIndex, parameter);
43+
return String.format("[%d] %s", invocationIndex, parameter);
4444
}
4545

4646
@Override
4747
public List<Extension> getAdditionalExtensions() {
4848
return Collections.singletonList(new ParameterResolver() {
4949
@Override
5050
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
51-
return parameterContext.getParameter().getType().equals(Integer.class);
51+
return true;
5252
}
5353

5454
@Override

0 commit comments

Comments
 (0)