Add toString method for EndpointRequestMatcher

See gh-33690
pull/33774/head
rishal 2 years ago committed by Moritz Halbritter
parent a3cd2dc539
commit c84399e705

@ -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();
}
}
/**

@ -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"));
}

Loading…
Cancel
Save