Closed
Description
Recently Spring Integration migrated to AssertJ and started using assertThatThrownBy()
instead of an ExpectedException
@Rule
.
Spring Boot also made the same migration but we opted to use assertThatExceptionOfType
rather than assertThatThrownBy
because we felt it was a little easier to use and because it has specialized versions for IllegalArguementException
, IOException
and IllegalStateException
.
For example, the following:
assertThatThrownBy(() -> listener.onMessage(mock(Message.class)))
.isInstanceOf(MessageConversionException.class)
.hasCauseInstanceOf(IllegalStateException.class);
would be:
assertThatExceptionOfType(MessageConversionException.class).isThrownBy(()->
listener.onMessage(mock(Message.class)))
.withCauseInstanceOf(IllegalStateException.class);
We also have a checkstyle rule to enforce the use of assertThatIllegalArgumentExceptionIsThrownBy()
etc.
I thought it was worth raising an issue in case you also wanted to consider it.