Override toString() in all RequestMatcher

It makes it easier to debug having custom
toString().

Fixes: gh-5446
This commit is contained in:
Rob Winch
2018-06-15 11:27:28 -05:00
parent 71986e5f42
commit c3177a84a3
7 changed files with 83 additions and 0 deletions

View File

@@ -216,4 +216,31 @@ public class MvcRequestMatcherTests {
new HttpRequestMethodNotSupportedException(this.request.getMethod()));
assertThat(this.matcher.matches(this.request)).isTrue();
}
@Test
public void toStringWhenAll() {
this.matcher.setMethod(HttpMethod.GET);
this.matcher.setServletPath("/spring");
assertThat(this.matcher.toString()).isEqualTo("Mvc [pattern='/path', servletPath='/spring', GET]");
}
@Test
public void toStringWhenHttpMethod() {
this.matcher.setMethod(HttpMethod.GET);
assertThat(this.matcher.toString()).isEqualTo("Mvc [pattern='/path', GET]");
}
@Test
public void toStringWhenServletPath() {
this.matcher.setServletPath("/spring");
assertThat(this.matcher.toString()).isEqualTo("Mvc [pattern='/path', servletPath='/spring']");
}
@Test
public void toStringWhenOnlyPattern() {
assertThat(this.matcher.toString()).isEqualTo("Mvc [pattern='/path']");
}
}

View File

@@ -90,4 +90,10 @@ public class ELRequestMatcherTests {
assertThat(requestMatcher.matches(request)).isFalse();
}
@Test
public void toStringThenFormatted() {
ELRequestMatcher requestMatcher = new ELRequestMatcher(
"hasHeader('User-Agent','MSIE')");
assertThat(requestMatcher.toString()).isEqualTo("EL [el=\"hasHeader('User-Agent','MSIE')\"]");
}
}

View File

@@ -108,6 +108,12 @@ public class RegexRequestMatcherTests {
assertThat(matcher.matches(request)).isFalse();
}
@Test
public void toStringThenFormatted() {
RegexRequestMatcher matcher = new RegexRequestMatcher("/blah", "GET");
assertThat(matcher.toString()).isEqualTo("Regex [pattern='/blah', GET]");
}
private HttpServletRequest createRequestWithNullMethod(String path) {
when(request.getQueryString()).thenReturn("doesntMatter");
when(request.getServletPath()).thenReturn(path);