Polishing
This commit is contained in:
@@ -99,7 +99,7 @@ class HttpServiceMethodTests {
|
||||
assertThat(voidEntity.getBody()).isNull();
|
||||
|
||||
List<String> list = service.getList();
|
||||
assertThat(list).containsExactly("exchangeForBody");
|
||||
assertThat(list).containsOnly("exchangeForBody");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,7 +183,7 @@ class HttpServiceMethodTests {
|
||||
assertThat(requestValues.getHttpMethod()).isEqualTo(HttpMethod.POST);
|
||||
assertThat(requestValues.getUriTemplate()).isEqualTo("/url");
|
||||
assertThat(requestValues.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
assertThat(requestValues.getHeaders().getAccept()).containsExactly(MediaType.APPLICATION_JSON);
|
||||
assertThat(requestValues.getHeaders().getAccept()).containsOnly(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,7 +201,7 @@ class HttpServiceMethodTests {
|
||||
assertThat(requestValues.getHttpMethod()).isEqualTo(HttpMethod.GET);
|
||||
assertThat(requestValues.getUriTemplate()).isEqualTo("/base");
|
||||
assertThat(requestValues.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_CBOR);
|
||||
assertThat(requestValues.getHeaders().getAccept()).containsExactly(MediaType.APPLICATION_CBOR);
|
||||
assertThat(requestValues.getHeaders().getAccept()).containsOnly(MediaType.APPLICATION_CBOR);
|
||||
|
||||
service.performPost();
|
||||
|
||||
@@ -209,7 +209,7 @@ class HttpServiceMethodTests {
|
||||
assertThat(requestValues.getHttpMethod()).isEqualTo(HttpMethod.POST);
|
||||
assertThat(requestValues.getUriTemplate()).isEqualTo("/base/url");
|
||||
assertThat(requestValues.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
assertThat(requestValues.getHeaders().getAccept()).containsExactly(MediaType.APPLICATION_JSON);
|
||||
assertThat(requestValues.getHeaders().getAccept()).containsOnly(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
@Test // gh-32049
|
||||
|
||||
@@ -22,7 +22,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.Principal;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -79,17 +80,16 @@ class RequestMappingHandlerMappingTests {
|
||||
void resolveEmbeddedValuesInPatterns() {
|
||||
this.handlerMapping.setEmbeddedValueResolver(value -> "/${pattern}/bar".equals(value) ? "/foo/bar" : value);
|
||||
|
||||
String[] patterns = new String[] { "/foo", "/${pattern}/bar" };
|
||||
String[] patterns = { "/foo", "/${pattern}/bar" };
|
||||
String[] result = this.handlerMapping.resolveEmbeddedValuesInPatterns(patterns);
|
||||
|
||||
assertThat(result).isEqualTo(new String[] { "/foo", "/foo/bar" });
|
||||
assertThat(result).containsExactly("/foo", "/foo/bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void pathPrefix() {
|
||||
this.handlerMapping.setEmbeddedValueResolver(value -> "/${prefix}".equals(value) ? "/api" : value);
|
||||
this.handlerMapping.setPathPrefixes(Collections.singletonMap(
|
||||
"/${prefix}", HandlerTypePredicate.forAnnotation(RestController.class)));
|
||||
this.handlerMapping.setPathPrefixes(Map.of("/${prefix}", HandlerTypePredicate.forAnnotation(RestController.class)));
|
||||
|
||||
Method method = ReflectionUtils.findMethod(UserController.class, "getUser");
|
||||
RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, UserController.class);
|
||||
@@ -102,8 +102,11 @@ class RequestMappingHandlerMappingTests {
|
||||
void resolveRequestMappingViaComposedAnnotation() {
|
||||
RequestMappingInfo info = assertComposedAnnotationMapping("postJson", "/postJson", RequestMethod.POST);
|
||||
|
||||
assertThat(info.getConsumesCondition().getConsumableMediaTypes().iterator().next().toString()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||
assertThat(info.getProducesCondition().getProducibleMediaTypes().iterator().next().toString()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||
Set<MediaType> consumableMediaTypes = info.getConsumesCondition().getConsumableMediaTypes();
|
||||
Set<MediaType> producibleMediaTypes = info.getProducesCondition().getProducibleMediaTypes();
|
||||
|
||||
assertThat(consumableMediaTypes).singleElement().hasToString(MediaType.APPLICATION_JSON_VALUE);
|
||||
assertThat(producibleMediaTypes).singleElement().hasToString(MediaType.APPLICATION_JSON_VALUE);
|
||||
}
|
||||
|
||||
@Test // SPR-14988
|
||||
@@ -111,7 +114,7 @@ class RequestMappingHandlerMappingTests {
|
||||
RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.POST);
|
||||
|
||||
ConsumesRequestCondition condition = requestMappingInfo.getConsumesCondition();
|
||||
assertThat(condition.getConsumableMediaTypes()).isEqualTo(Collections.singleton(MediaType.APPLICATION_XML));
|
||||
assertThat(condition.getConsumableMediaTypes()).containsOnly(MediaType.APPLICATION_XML);
|
||||
}
|
||||
|
||||
@Test // gh-22010
|
||||
|
||||
@@ -143,7 +143,7 @@ class RequestMappingHandlerMappingTests {
|
||||
mapping.setApplicationContext(wac);
|
||||
mapping.afterPropertiesSet();
|
||||
|
||||
assertThat(extensions).isEqualTo(Collections.singleton("json"));
|
||||
assertThat(extensions).containsOnly("json");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,14 +167,12 @@ class RequestMappingHandlerMappingTests {
|
||||
|
||||
@PathPatternsParameterizedTest
|
||||
void resolveEmbeddedValuesInPatterns(RequestMappingHandlerMapping mapping) {
|
||||
mapping.setEmbeddedValueResolver(
|
||||
value -> "/${pattern}/bar".equals(value) ? "/foo/bar" : value
|
||||
);
|
||||
mapping.setEmbeddedValueResolver(value -> "/${pattern}/bar".equals(value) ? "/foo/bar" : value);
|
||||
|
||||
String[] patterns = new String[] { "/foo", "/${pattern}/bar" };
|
||||
String[] patterns = { "/foo", "/${pattern}/bar" };
|
||||
String[] result = mapping.resolveEmbeddedValuesInPatterns(patterns);
|
||||
|
||||
assertThat(result).isEqualTo(new String[] { "/foo", "/foo/bar" });
|
||||
assertThat(result).containsExactly("/foo", "/foo/bar");
|
||||
}
|
||||
|
||||
@PathPatternsParameterizedTest
|
||||
@@ -188,7 +186,7 @@ class RequestMappingHandlerMappingTests {
|
||||
RequestMappingInfo info = mapping.getMappingForMethod(method, UserController.class);
|
||||
|
||||
assertThat(info).isNotNull();
|
||||
assertThat(info.getPatternValues()).isEqualTo(Collections.singleton("/api/user/{id}"));
|
||||
assertThat(info.getPatternValues()).containsOnly("/api/user/{id}");
|
||||
}
|
||||
|
||||
@PathPatternsParameterizedTest // gh-23907
|
||||
@@ -226,10 +224,11 @@ class RequestMappingHandlerMappingTests {
|
||||
RequestMappingInfo info = assertComposedAnnotationMapping(
|
||||
mapping, "postJson", "/postJson", RequestMethod.POST);
|
||||
|
||||
assertThat(info.getConsumesCondition().getConsumableMediaTypes().iterator().next().toString())
|
||||
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||
assertThat(info.getProducesCondition().getProducibleMediaTypes().iterator().next().toString())
|
||||
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||
Set<MediaType> consumableMediaTypes = info.getConsumesCondition().getConsumableMediaTypes();
|
||||
Set<MediaType> producibleMediaTypes = info.getProducesCondition().getProducibleMediaTypes();
|
||||
|
||||
assertThat(consumableMediaTypes).singleElement().hasToString(MediaType.APPLICATION_JSON_VALUE);
|
||||
assertThat(producibleMediaTypes).singleElement().hasToString(MediaType.APPLICATION_JSON_VALUE);
|
||||
}
|
||||
|
||||
@Test // SPR-14988
|
||||
@@ -237,7 +236,7 @@ class RequestMappingHandlerMappingTests {
|
||||
RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.POST);
|
||||
|
||||
ConsumesRequestCondition condition = requestMappingInfo.getConsumesCondition();
|
||||
assertThat(condition.getConsumableMediaTypes()).isEqualTo(Collections.singleton(MediaType.APPLICATION_XML));
|
||||
assertThat(condition.getConsumableMediaTypes()).containsOnly(MediaType.APPLICATION_XML);
|
||||
}
|
||||
|
||||
@PathPatternsParameterizedTest // gh-22010
|
||||
@@ -458,10 +457,10 @@ class RequestMappingHandlerMappingTests {
|
||||
assertThat(info).isNotNull();
|
||||
|
||||
Set<String> paths = info.getPatternValues();
|
||||
assertThat(paths).containsExactly(path);
|
||||
assertThat(paths).containsOnly(path);
|
||||
|
||||
Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
|
||||
assertThat(methods).containsExactly(requestMethod);
|
||||
assertThat(methods).containsOnly(requestMethod);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user