Polishing

This commit is contained in:
Sam Brannen
2024-01-23 11:10:21 +01:00
parent 5faace0eb3
commit 45a1f98bd6
3 changed files with 28 additions and 26 deletions

View File

@@ -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