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:
Rossen Stoyanchev
2019-07-13 10:56:12 +01:00
parent 68c99dafcf
commit c32299f734
4 changed files with 15 additions and 8 deletions

View File

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