Improve parameter-based content negotiation

Closes gh-36925
This commit is contained in:
rstoyanchev
2026-06-22 10:42:51 +01:00
parent cc0ca1b6a5
commit 5059bbd58e
4 changed files with 23 additions and 10 deletions
@@ -49,7 +49,7 @@ class MappingContentNegotiationStrategyTests {
}
@Test
void resolveMediaTypesViaMediaTypeFactory() throws Exception {
void resolveMediaTypesViaFactory() throws Exception {
Map<String, MediaType> mapping = null;
TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy("xml", mapping);
@@ -68,6 +68,15 @@ class MappingContentNegotiationStrategyTests {
.isInstanceOf(HttpMediaTypeNotAcceptableException.class);
}
@Test
void resolveMediaTypesInvalidKey() {
Map<String, MediaType> mapping = null;
TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy("not.json", mapping);
assertThatThrownBy(() -> strategy.resolveMediaTypes(null))
.isInstanceOf(HttpMediaTypeNotAcceptableException.class);
}
@Test
void resolveMediaTypesNullKey() throws Exception {
Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
@@ -75,6 +75,8 @@ class MappingMediaTypeFileExtensionResolverTests {
map.put("jSoN", MediaType.APPLICATION_JSON);
MappingMediaTypeFileExtensionResolver resolver = new MappingMediaTypeFileExtensionResolver(map);
map.forEach(resolver::addMapping);
assertThat(resolver.getAllFileExtensions()).containsExactly("json");
}