@@ -52,16 +52,12 @@ public void givenTwoChannelHandlers_testExceptionHandlingInHttpMessageHandler()
5252 "/calculate?a=10&b=5" );
5353 wrongHttpRequest .headers ().add ("Operator" , "Add" );
5454
55- Throwable thrownException = catchThrowable (() -> {
56- // send invalid HTTP request to server and expect and error
57- channel .pipeline ().fireChannelRead (wrongHttpRequest );
58- channel .checkException ();
59- Assertions .failBecauseExceptionWasNotThrown (UnsupportedOperationException .class );
60- });
61-
62- assertThat (thrownException )
63- .isInstanceOf (UnsupportedOperationException .class )
64- .hasMessage ("HTTP method not supported" );
55+ assertThatThrownBy (() -> {
56+ // send invalid HTTP request to server and expect and error
57+ channel .pipeline ().fireChannelRead (wrongHttpRequest );
58+ channel .checkException ();
59+ }).isInstanceOf (UnsupportedOperationException .class )
60+ .hasMessage ("HTTP method not supported" );
6561
6662 FullHttpResponse errorHttpResponse = channel .readOutbound ();
6763 String errorHttpResponseContent = errorHttpResponse .content ().toString (Charset .defaultCharset ());
@@ -77,15 +73,11 @@ public void givenTwoChannelHandlers_testExceptionHandlingInCalculatorOperationHa
7773 "/calculate?a=10&b=5" );
7874 wrongHttpRequest .headers ().add ("Operator" , "Invalid_operation" );
7975
80- Throwable thrownException = catchThrowable (() -> {
81- // send invalid HTTP request to server and expect and error
82- channel .writeInbound (wrongHttpRequest );
83- Assertions .failBecauseExceptionWasNotThrown (IllegalArgumentException .class );
84- });
85-
86- // the HttpMessageHandler does not handle the exception and throws it down the
87- // pipeline
88- assertThat (thrownException ).isInstanceOf (IllegalArgumentException .class ).hasMessage ("Operation not defined" );
76+ // the HttpMessageHandler does not handle the exception and throws it down the pipeline
77+ assertThatThrownBy (() -> {
78+ channel .writeInbound (wrongHttpRequest );
79+ }).isInstanceOf (IllegalArgumentException .class )
80+ .hasMessage ("Operation not defined" );
8981
9082 // the outbound message is a HTTP response with the status code 500
9183 FullHttpResponse errorHttpResponse = channel .readOutbound ();
0 commit comments