Override toString() in all RequestMatcher
It makes it easier to debug having custom toString(). Fixes: gh-5446
This commit is contained in:
@@ -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']");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')\"]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user