Use HttpMessageNotWritableException instead of ISE
As a follow-up to the recent commit #37f9ce, this change replaces the raised IllegalStateException with HttpMessageNotWritableException. See gh-23205
This commit is contained in:
@@ -47,6 +47,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||
@@ -59,7 +60,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.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyCollection;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
@@ -325,10 +326,11 @@ public class HttpEntityMethodProcessorMockTests {
|
||||
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");
|
||||
assertThatThrownBy(() ->
|
||||
processor.handleReturnValue(
|
||||
returnValue, returnTypeResponseEntity, mavContainer, webRequest))
|
||||
.isInstanceOf(HttpMessageNotWritableException.class)
|
||||
.hasMessageContaining("with preset Content-Type");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user