Merge pull request #33690 from devrishal

* pr/33690:
  Add toString method for EndpointRequestMatcher

Closes gh-33690
This commit is contained in:
Moritz Halbritter 2023-01-09 12:39:31 +01:00
commit 29b7e518a5
2 changed files with 46 additions and 0 deletions

View File

@ -273,6 +273,24 @@ public final class EndpointRequest {
.collect(Collectors.toList());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (this.includes.isEmpty()) {
sb.append("EndpointRequest [includes='[").append("*").append("]'");
}
else {
sb.append("EndpointRequest [includes='")
.append(this.includes.stream().map(this::getEndpointId).collect(Collectors.toList()))
.append("'");
}
sb.append(", Excludes='")
.append(this.excludes.stream().map(this::getEndpointId).collect(Collectors.toList())).append("'");
sb.append(", IncludeLinks='").append(this.includeLinks).append("'");
sb.append("]");
return sb.toString();
}
}
/**

View File

@ -216,6 +216,34 @@ class EndpointRequestTests {
assertMatcher(matcher, (PathMappedEndpoints) null).doesNotMatch("/actuator/bar");
}
@Test
void toStringIncludedEndpoints() {
RequestMatcher matcher = EndpointRequest.to("foo", "bar");
assertThat(matcher.toString())
.isEqualTo("EndpointRequest [includes='[foo, bar]', Excludes='[]', IncludeLinks='false']");
}
@Test
void toStringEmptyIncludedEndpoints() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
assertThat(matcher.toString())
.isEqualTo("EndpointRequest [includes='[*]', Excludes='[]', IncludeLinks='true']");
}
@Test
void toStringIncludedEndpointsClasses() {
RequestMatcher matcher = EndpointRequest.to(FooEndpoint.class).excluding("bar");
assertThat(matcher.toString())
.isEqualTo("EndpointRequest [includes='[foo]', Excludes='[bar]', IncludeLinks='false']");
}
@Test
void toStringIncludedExcludedEndpoints() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint().excluding("bar").excludingLinks();
assertThat(matcher.toString())
.isEqualTo("EndpointRequest [includes='[*]', Excludes='[bar]', IncludeLinks='false']");
}
private RequestMatcherAssert assertMatcher(RequestMatcher matcher) {
return assertMatcher(matcher, mockPathMappedEndpoints("/actuator"));
}