mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Merge pull request #33690 from devrishal
* pr/33690: Add toString method for EndpointRequestMatcher Closes gh-33690
This commit is contained in:
commit
29b7e518a5
@ -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…
Reference in New Issue
Block a user