@ -20,6 +20,7 @@ import java.io.FileNotFoundException;
@@ -20,6 +20,7 @@ import java.io.FileNotFoundException;
import java.io.IOException ;
import java.net.BindException ;
import java.net.SocketException ;
import java.util.Set ;
import jakarta.servlet.http.HttpServletRequest ;
import jakarta.servlet.http.HttpServletResponse ;
@ -100,14 +101,21 @@ class ExceptionHandlerMethodResolverTests {
@@ -100,14 +101,21 @@ class ExceptionHandlerMethodResolverTests {
@Test
void shouldThrowExceptionWhenAmbiguousExceptionMapping ( ) {
assertThatIllegalStateException ( ) . isThrownBy ( ( ) - >
new ExceptionHandlerMethodResolver ( AmbiguousController . class ) ) ;
assertThatIllegalStateException ( )
. isThrownBy ( ( ) - > new ExceptionHandlerMethodResolver ( AmbiguousController . class ) ) ;
}
@Test
void shouldThrowExceptionWhenNoExceptionMapping ( ) {
assertThatIllegalStateException ( ) . isThrownBy ( ( ) - >
new ExceptionHandlerMethodResolver ( NoExceptionController . class ) ) ;
assertThatIllegalStateException ( )
. isThrownBy ( ( ) - > new ExceptionHandlerMethodResolver ( NoExceptionController . class ) ) ;
}
@Test // gh-35587
void shouldRetainOriginalOrderOfProducibleMediaTypes ( ) {
ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver ( MediaTypeController . class ) ;
Set < MediaType > producibleTypes = resolver . resolveExceptionMapping ( new IllegalArgumentException ( ) , MediaType . TEXT_HTML ) . getProducibleTypes ( ) ;
assertThat ( MediaType . toString ( producibleTypes ) ) . isEqualTo ( "text/html, */*" ) ;
}
@Test
@ -131,15 +139,15 @@ class ExceptionHandlerMethodResolverTests {
@@ -131,15 +139,15 @@ class ExceptionHandlerMethodResolverTests {
@Test
void shouldThrowExceptionWhenInvalidMediaTypeMapping ( ) {
assertThatIllegalStateException ( ) . isThrownBy ( ( ) - >
new ExceptionHandlerMethodResolver ( InvalidMediaTypeController . class ) )
assertThatIllegalStateException ( )
. isThrownBy ( ( ) - > new ExceptionHandlerMethodResolver ( InvalidMediaTypeController . class ) )
. withMessageContaining ( "Invalid media type [invalid-mediatype] declared on @ExceptionHandler" ) ;
}
@Test
void shouldThrowExceptionWhenAmbiguousMediaTypeMapping ( ) {
assertThatIllegalStateException ( ) . isThrownBy ( ( ) - >
new ExceptionHandlerMethodResolver ( AmbiguousMediaTypeController . class ) )
assertThatIllegalStateException ( )
. isThrownBy ( ( ) - > new ExceptionHandlerMethodResolver ( AmbiguousMediaTypeController . class ) )
. withMessageContaining ( "Ambiguous @ExceptionHandler method mapped for [ExceptionHandler{exceptionType=java.lang.IllegalArgumentException, mediaType=application/json}]" )
. withMessageContaining ( "AmbiguousMediaTypeController.handleJson()" )
. withMessageContaining ( "AmbiguousMediaTypeController.handleJsonToo()" ) ;