Skip to content

Commit 985efed

Browse files
committed
Use Java 17
1 parent b556df1 commit 985efed

File tree

6 files changed

+225
-214
lines changed

6 files changed

+225
-214
lines changed

java/src/test/java/io/cucumber/cucumberexpressions/CucumberExpressionTest.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.cucumber.cucumberexpressions;
22

3+
import org.hamcrest.CoreMatchers;
34
import org.jspecify.annotations.NullMarked;
45
import org.jspecify.annotations.Nullable;
56
import org.junit.jupiter.api.Test;
@@ -25,12 +26,16 @@
2526
import java.util.Comparator;
2627
import java.util.List;
2728
import java.util.Locale;
29+
import java.util.Map;
30+
import java.util.Objects;
2831
import java.util.stream.Collectors;
2932

3033
import static java.nio.file.Files.newDirectoryStream;
3134
import static java.nio.file.Files.newInputStream;
3235
import static java.util.Arrays.asList;
3336
import static java.util.Collections.singletonList;
37+
import static java.util.Objects.requireNonNull;
38+
import static org.hamcrest.CoreMatchers.nullValue;
3439
import static org.hamcrest.MatcherAssert.assertThat;
3540
import static org.hamcrest.Matchers.equalTo;
3641
import static org.hamcrest.core.Is.is;
@@ -57,34 +62,29 @@ static List<Path> acceptance_tests_pass() throws IOException {
5762
void acceptance_tests_pass(@ConvertWith(Converter.class) Expectation expectation) {
5863
if (expectation.exception == null) {
5964
CucumberExpression expression = new CucumberExpression(expectation.expression, parameterTypeRegistry);
60-
List<Argument<?>> match = expression.match(expectation.text);
65+
List<Argument<?>> match = expression.match(requireNonNull(expectation.text));
6166
List<?> values = match == null ? null : match.stream()
6267
.map(Argument::getValue)
6368
.collect(Collectors.toList());
6469

65-
assertThat(values, CustomMatchers.equalOrCloseTo(expectation.expectedArgs));
70+
if (expectation.expectedArgs == null) {
71+
assertThat(values, nullValue());
72+
} else {
73+
assertThat(values, CustomMatchers.equalOrCloseTo(expectation.expectedArgs));
74+
}
6675
} else {
6776
Executable executable = () -> {
6877
CucumberExpression expression = new CucumberExpression(expectation.expression, parameterTypeRegistry);
69-
expression.match(expectation.text);
78+
if (expectation.text != null) {
79+
expression.match(expectation.text);
80+
}
7081
};
7182
CucumberExpressionException exception = assertThrows(CucumberExpressionException.class, executable);
7283
assertThat(exception.getMessage(), equalTo(expectation.exception));
7384
}
7485
}
7586

76-
static class Expectation {
77-
public final String expression;
78-
public final String text;
79-
public final List<?> expectedArgs;
80-
public final @Nullable String exception;
81-
82-
Expectation(String expression, String text, List<?> expectedArgs, String exception) {
83-
this.expression = expression;
84-
this.text = text;
85-
this.expectedArgs = expectedArgs;
86-
this.exception = exception;
87-
}
87+
public record Expectation(String expression, @Nullable String text, @Nullable List<?> expectedArgs, @Nullable String exception) {
8888
}
8989

9090
@NullMarked
@@ -100,7 +100,13 @@ public Expectation convert(@Nullable Object source, ParameterContext context) th
100100
try {
101101
Path path = (Path) source;
102102
InputStream inputStream = newInputStream(path);
103-
return yaml.loadAs(inputStream, Expectation.class);
103+
Map<String, ?> document = yaml.loadAs(inputStream, Map.class);
104+
return new Expectation(
105+
(String) requireNonNull(document.get("expression")),
106+
(String) document.get("text"),
107+
(List<?>) document.get("expected_args"),
108+
(String) document.get("exception")
109+
);
104110
} catch (IOException e) {
105111
throw new ArgumentConversionException("Could not load " + source, e);
106112
}

java/src/test/java/io/cucumber/cucumberexpressions/CustomParameterTypeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void warns_when_CucumberExpression_parameters_with_multiple_capture_groups_has_a
9494
"coordinate",
9595
"(\\d+),\\s*(\\d+),\\s*(\\d+)",
9696
Coordinate.class,
97-
(@Nullable String[] args) -> {
97+
(@Nullable String arg) -> {
9898
throw new IllegalStateException();
9999
},
100100
false,

0 commit comments

Comments
 (0)