Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Response matchRedirect(String url, Integer statusCode, String urlRegex) {
- return
- given().
- redirects().follow(false).and().redirects().max(0).
- expect().
- statusCode(statusCode).
- header("Location", **matches**(urlRegex)).
- when().get(url);
- }
- import org.hamcrest.BaseMatcher;
- import org.hamcrest.Description;
- public class RegexMatcher extends BaseMatcher<Object>{
- private final String regex;
- public RegexMatcher(String regex){
- this.regex = regex;
- }
- public boolean matches(Object o){
- return ((String)o).matches(regex);
- }
- public void describeTo(Description description){
- description.appendText("matches regex=");
- }
- public static RegexMatcher matches(String regex){
- return new RegexMatcher(regex);
- }
- }
- import org.hamcrest.BaseMatcher;
- import org.hamcrest.Description;
- import org.hamcrest.Matcher;
- public class CustomMatchers {
- public static Matcher<String> matchesRegex(final String regex) {
- return new BaseMatcher<String>() {
- public boolean matches(final Object item) {
- return ((String) item).matches(regex);
- }
- public void describeTo(final Description description) {
- description.appendText("should match regex: " + regex);
- }
- };
- }
- }
- public Response matchRedirect(String url, Integer statusCode, String urlRegex) {
- return
- given().
- redirects().follow(false).and().redirects().max(0).
- expect().
- statusCode(statusCode).
- header("Location", CustomMatchers.matchesRegex(urlRegex)).
- when().get(url);
- }
Add Comment
Please, Sign In to add comment