Return 500 (not 406) if content-type was preset
If content-type is preset in the returned ResponseEntity, then any failure to find a matching converter is a server error. Closes gh-23205
This commit is contained in:
@@ -59,6 +59,7 @@ import static java.time.Instant.ofEpochMilli;
|
||||
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyCollection;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
@@ -315,6 +316,21 @@ public class HttpEntityMethodProcessorMockTests {
|
||||
processor.handleReturnValue(returnValue, returnTypeResponseEntity, mavContainer, webRequest));
|
||||
}
|
||||
|
||||
@Test // gh-23205
|
||||
public void shouldFailWithServerErrorIfContentTypeFromResponseEntity() {
|
||||
ResponseEntity<String> returnValue = ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_XML)
|
||||
.body("<foo/>");
|
||||
|
||||
given(stringHttpMessageConverter.canWrite(String.class, null)).willReturn(true);
|
||||
given(stringHttpMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(TEXT_PLAIN));
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() ->
|
||||
processor.handleReturnValue(returnValue, returnTypeResponseEntity, mavContainer, webRequest))
|
||||
.withMessageContaining("with preset Content-Type");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailHandlingWhenConverterCannotWrite() throws Exception {
|
||||
String body = "Foo";
|
||||
|
||||
Reference in New Issue
Block a user