Skip to content

Commit d112517

Browse files
committed
Introduced parameterized JVMTest
1 parent 607aea4 commit d112517

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

testlib/src/test/java/com/diffplug/spotless/JvmTest.java

+22-23
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222

2323
import java.util.Arrays;
2424
import java.util.function.Consumer;
25+
import java.util.stream.Stream;
2526

2627
import org.junit.jupiter.api.BeforeEach;
2728
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.params.ParameterizedTest;
30+
import org.junit.jupiter.params.provider.Arguments;
31+
import org.junit.jupiter.params.provider.MethodSource;
2832

2933
class JvmTest {
3034

@@ -44,32 +48,27 @@ void supportAdd() {
4448
assertThat(testSupport.toString()).contains(String.format("%s alternatives", TEST_NAME));
4549
}
4650

47-
@Test
48-
void supportAddVerification() {
49-
Arrays.<Consumer<Jvm.Support<String>>> asList(
50-
s -> {
51-
s.add(1, "1.a");
52-
}, //Not a semantic version
53-
s -> {
54-
s.add(1, "0.1").add(1, "1.0");
55-
}, //forgot to adapt JVM version
56-
s -> {
57-
s.add(1, "0.1").add(2, "0.1");
58-
}, //forgot to adapt formatter version
59-
s -> {
60-
s.add(1, "1.0").add(2, "0.1");
61-
}, //higher formatter version requires lower Java version
62-
s -> {
63-
s.add(2, "0.1").add(1, "1.0");
64-
} //lower formatter version requires higher Java version
65-
).stream().forEach(configuration -> {
66-
Jvm.Support<String> support = Jvm.support(TEST_NAME);
67-
assertThrows(IllegalArgumentException.class, () -> {
68-
configuration.accept(support);
69-
});
51+
@ParameterizedTest(name = "{index} {1}")
52+
@MethodSource
53+
void supportAddFailsFor(Consumer<Jvm.Support<String>> configuration, String nameNotUsed) {
54+
assertThrows(IllegalArgumentException.class, () -> {
55+
configuration.accept(testSupport);
7056
});
7157
}
7258

59+
private static Stream<Arguments> supportAddFailsFor() {
60+
return Stream.of(
61+
testCase(s -> s.add(1, "1.a"), "Non-semantic version"),
62+
testCase(s -> s.add(1, "1").add(1, "2"), "Duplicated JVM version"),
63+
testCase(s -> s.add(1, "1").add(2, "1"), "Duplicated formatter version"),
64+
testCase(s -> s.add(1, "1").add(2, "0"), "Higher JVM for lower formatter version"),
65+
testCase(s -> s.add(2, "0").add(1, "1"), "Lower JVM for higher formatter version"));
66+
}
67+
68+
private static Arguments testCase(Consumer<Jvm.Support<String>> config, String name) {
69+
return Arguments.of(config, name);
70+
}
71+
7372
@Test
7473
void supportEmptyConfiguration() {
7574
assertNull(testSupport.getRecommendedFormatterVersion(), "No formatter version is configured");

0 commit comments

Comments
 (0)