SetErrorMessage extends GenericMailet { @Override public void init() throws MessagingException { errorMessage = getInitParameterAsOptional("errorMessage") .filter(Predicate.not(String::isEmpty)) .orElseThrow(() -> new IllegalStateException("'errorMessage' needs to be specified and cannot be empty")); }  @Override void init(); @Override void service(Mail mail);  }
@Test void initShouldThrowWhenNoErrorMessage() { assertThatThrownBy(() -> testee.init(FakeMailetConfig.builder().build())) .isInstanceOf(IllegalStateException.class) .hasMessage("'errorMessage' needs to be specified and cannot be empty"); }
@Test void initShouldThrowOnEmptyErrorMessage() { assertThatThrownBy(() -> testee.init(FakeMailetConfig.builder() .setProperty("errorMessage", "") .build())) .isInstanceOf(IllegalStateException.class) .hasMessage("'errorMessage' needs to be specified and cannot be empty"); }