Skip to content

Commit

Permalink
test: add a step to check values in a list
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeltour committed Jul 6, 2023
1 parent f7b5dd9 commit 65828c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/test/java/org/w3c/epubcheck/test/JSONReportAssertionSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJson;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

import java.util.List;

import io.cucumber.java.en.Then;

public class JSONReportAssertionSteps
Expand Down Expand Up @@ -40,6 +44,24 @@ public void jsonValueIs(String path, String value)
assertThat(report.getOutput(), hasJsonPath(path, equalTo(value)));
}

@Then("JSON at {string} is {bool}")
public void jsonValueIs(String path, Boolean value)
{
assertThat(report.getOutput(), hasJsonPath(path, equalTo(value)));
}

@Then("JSON at {string} is:")
public void jsonValueIs(String path, List<String> values)
{
assertThat(report.getOutput(), hasJsonPath(path, equalTo(values)));
}

@Then("JSON at {string} is empty")
public void jsonValueIs(String path)
{
assertThat(report.getOutput(), hasJsonPath(path, is(empty())));
}

@Then("JSON at {string} is not null")
public void jsonValueIsNotNull(String path)
{
Expand All @@ -51,4 +73,16 @@ public void jsonValuesAreNotNull(String path)
{
assertThat(report.getOutput(), hasJsonPath(path, everyItem(notNullValue())));
}

@Then("JSON at {string} are all {string}")
public void jsonValuesAreAll(String path, String value)
{
assertThat(report.getOutput(), hasJsonPath(path, everyItem(equalTo(value))));
}

@Then("JSON at {string} are all {bool}")
public void jsonValuesAreAll(String path, Boolean value)
{
assertThat(report.getOutput(), hasJsonPath(path, everyItem(equalTo(value))));
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/w3c/epubcheck/test/ParameterTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public MessageId apply(String input)
}

};

@ParameterType("true|false")
public Boolean bool(String value) {
return Boolean.valueOf(value);
}

@ParameterType("?i:(full publication|((Media Overlays|Navigation|Package|SVG Content|XHTML Content) Document))")
public CheckerMode checkerMode(String mode)
Expand Down

0 comments on commit 65828c2

Please sign in to comment.