11package io .cucumber .cucumberexpressions ;
22
3+ import org .hamcrest .CoreMatchers ;
34import org .jspecify .annotations .NullMarked ;
45import org .jspecify .annotations .Nullable ;
56import org .junit .jupiter .api .Test ;
2526import java .util .Comparator ;
2627import java .util .List ;
2728import java .util .Locale ;
29+ import java .util .Map ;
30+ import java .util .Objects ;
2831import java .util .stream .Collectors ;
2932
3033import static java .nio .file .Files .newDirectoryStream ;
3134import static java .nio .file .Files .newInputStream ;
3235import static java .util .Arrays .asList ;
3336import static java .util .Collections .singletonList ;
37+ import static java .util .Objects .requireNonNull ;
38+ import static org .hamcrest .CoreMatchers .nullValue ;
3439import static org .hamcrest .MatcherAssert .assertThat ;
3540import static org .hamcrest .Matchers .equalTo ;
3641import 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 }
0 commit comments