generator.server.springboot.cucumber.rest.HeaderAssertions.mustache Maven / Gradle / Ivy
package {{packageName}}.cucumber.rest;
import static org.assertj.core.api.Assertions.*;
import java.util.List;
class HeaderAssertions {
private final String header;
HeaderAssertions(String header) {
this.header = header;
assertThat(CucumberRestTestContext.getResponseHeader(header)).as("Can't find header " + header).isNotEmpty();
}
public void containing(String value) {
List values = CucumberRestTestContext.getResponseHeader(header);
assertThat(values)
.as("Expecting header " + header + " to contain " + value + " but can't find it, current values are " + displayValues(values))
.contains(value);
}
public void startingWith(String prefix) {
List values = CucumberRestTestContext.getResponseHeader(header);
assertThat(values)
.as("Expecting header " + header + " to start with " + prefix + " but can't find it, current values are " + displayValues(values))
.anyMatch(content -> content.startsWith(prefix));
}
private String displayValues(List values) {
return String.join(", ", values);
}
}