Skip to content

Commit 96d0c6d

Browse files
committed
Introduce internal RecordsArguments interface
Related issue: #4421
1 parent f10ba0d commit 96d0c6d

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

junit-jupiter-params/junit-jupiter-params.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id("junitbuild.shadow-conventions")
44
id("junitbuild.jmh-conventions")
55
id("junitbuild.native-image-properties")
6+
`java-test-fixtures`
67
}
78

89
description = "JUnit Jupiter Params"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2015-2025 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package org.junit.jupiter.params.provider;
12+
13+
import java.util.Arrays;
14+
15+
import org.junit.platform.commons.support.ReflectionSupport;
16+
17+
public interface RecordArguments extends Arguments {
18+
19+
@Override
20+
default Object[] get() {
21+
return Arrays.stream(getClass().getRecordComponents()) //
22+
.map(component -> ReflectionSupport.invokeMethod(component.getAccessor(), this)) //
23+
.toArray();
24+
}
25+
26+
}

platform-tests/platform-tests.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ dependencies {
4646
testImplementation(testFixtures(projects.junitPlatformLauncher))
4747
testImplementation(projects.junitJupiterEngine)
4848
testImplementation(testFixtures(projects.junitJupiterEngine))
49+
testImplementation(testFixtures(projects.junitJupiterParams))
4950
testImplementation(libs.apiguardian)
5051
testImplementation(libs.classgraph)
5152
testImplementation(libs.jfrunit) {

platform-tests/src/test/java/org/junit/platform/launcher/core/DiscoveryIssueCollectorTests.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.junit.jupiter.params.ParameterizedTest;
2828
import org.junit.jupiter.params.provider.MethodSource;
29+
import org.junit.jupiter.params.provider.RecordArguments;
2930
import org.junit.platform.engine.DiscoveryIssue;
3031
import org.junit.platform.engine.DiscoveryIssue.Severity;
3132
import org.junit.platform.engine.DiscoverySelector;
@@ -44,14 +45,15 @@ class DiscoveryIssueCollectorTests {
4445

4546
@ParameterizedTest(name = "{0}")
4647
@MethodSource("pairs")
47-
void reportsFailedResolutionResultAsDiscoveryIssue(Pair pair) {
48+
void reportsFailedResolutionResultAsDiscoveryIssue(DiscoverySelector selector, TestSource source) {
4849
var collector = new DiscoveryIssueCollector(mock());
4950
var failure = SelectorResolutionResult.failed(new RuntimeException("boom"));
50-
collector.selectorProcessed(UniqueId.forEngine("dummy"), pair.selector, failure);
51+
collector.selectorProcessed(UniqueId.forEngine("dummy"), selector, failure);
5152

52-
var expectedIssue = DiscoveryIssue.builder(Severity.ERROR, pair.selector + " resolution failed") //
53+
var expectedIssue = DiscoveryIssue.builder(Severity.ERROR, selector + " resolution failed") //
5354
.cause(failure.getThrowable()) //
54-
.source(pair.source).build();
55+
.source(source) //
56+
.build();
5557
assertThat(collector.toNotifier().getAllIssues()).containsExactly(expectedIssue);
5658
}
5759

@@ -80,6 +82,6 @@ public static Stream<Pair> pairs() {
8082
);
8183
}
8284

83-
record Pair(DiscoverySelector selector, TestSource source) {
85+
record Pair(DiscoverySelector selector, TestSource source) implements RecordArguments {
8486
}
8587
}

0 commit comments

Comments
 (0)