Вот класс исключения:
Код: Выделить всё
public class SomeException extends RuntimeException {
private final Set something;
public SomeException (String message, Set something) {
super(message);
this.something = something;
}
public Set getSomething() {
return something;
}
}
Код: Выделить всё
assertThatThrownBy(() -> service.doSomething())
.isInstanceOf(SomeException.class)
.hasMessageStartingWith("SomeException has 1,2,3,4 in something field. I want assert that")
. ??? check that SomeException.getSomething() has 1,2,3,4 ???
Обновление:
Код: Выделить всё
SomeException throwable = (SomeException) catchThrowable(() -> service.doSomething(
assertThat(throwable)
.hasMessageStartingWith("extracting() bellow still think we're working with Throwable")
.extracting(SomeException::getSomething
Подробнее здесь: [url]https://stackoverflow.com/questions/64541192/assertthatthrownby-check-field-on-custom-exception[/url]
Мобильная версия