Skip to content

Commit

Permalink
8296283: JUnit5 tests using Params API fails to compile
Browse files Browse the repository at this point in the history
Reviewed-by: kcr
  • Loading branch information
arapte committed Nov 8, 2022
1 parent 7f17447 commit b08f135
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1988,10 +1988,10 @@ allprojects {
testImplementation group: "org.hamcrest", name: "hamcrest-core", version: "1.3"
testImplementation group: "org.junit.jupiter", name: "junit-jupiter", version: "5.8.1"
testImplementation group: "org.junit.jupiter", name: "junit-jupiter-api", version: "5.8.1"
testImplementation group: "org.junit.jupiter", name: "junit-jupiter-params", version: "5.8.1"
testImplementation group: "org.opentest4j", name: "opentest4j", version: "1.2.0"
testRuntimeOnly group: "org.apiguardian", name: "apiguardian-api", version: "1.1.2"
testRuntimeOnly group: "org.junit.jupiter", name: "junit-jupiter-engine", version: "5.8.1"
testRuntimeOnly group: "org.junit.jupiter", name: "junit-jupiter-params", version: "5.8.1"
testRuntimeOnly group: "org.junit.platform", name: "junit-platform-commons", version: "1.8.1"
testRuntimeOnly group: "org.junit.platform", name: "junit-platform-engine", version: "1.8.1"
testRuntimeOnly group: "org.junit.vintage", name: "junit-vintage-engine", version: "5.8.1"
Expand Down
29 changes: 29 additions & 0 deletions modules/javafx.base/src/test/java/test/JUnit5Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@

package test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.api.Test;

public class JUnit5Test {
Expand All @@ -39,4 +43,29 @@ void junit5ShouldWork() {
assertNotNull(this);
System.err.println("JUnit 5 test working!");
}

static int callCount;
static int[] intValues = {1, 2, 3};

@ValueSource(ints = {1, 2, 3})
@ParameterizedTest
void testParameterizedTest(int value) {
boolean match = false;
for (int i = 0; i < intValues.length; i++) {
if (value == intValues[i]) {
match = true;
intValues[i] = 0;
break;
}
}
callCount++;

assertTrue(match, "Received incorrect value as parameter");
assertTrue(callCount <= intValues.length, "Test function called more than number of ValueSources");
if (callCount == intValues.length) {
for (int i : intValues) {
assertEquals(0, i, "Test method not called for Value " + i);
}
}
}
}

1 comment on commit b08f135

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.