HasException extends GenericMatcher { @Override public void init() throws MessagingException { try { String exceptionClassName = getCondition().trim(); this.exceptionClass = castToThrowable(Class.forName(exceptionClassName)); } catch (ClassNotFoundException e) { throw new MessagingException("Specified exception class not found.", e); } }  @Override Collection<MailAddress> match(Mail mail); @Override void init(); @Override String getMatcherInfo();  }
@Test public void initShouldRaiseMessagingExceptionWhenInvalidClassName() throws MessagingException { FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("HasException") .condition("java.lang.InvalidClassName") .build(); assertThatThrownBy(() -> testee.init(matcherConfig)).isInstanceOf(MessagingException.class); }
@Test public void initShouldRaiseMessagingExceptionWhenClassNameIsNotException() throws MessagingException { FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("HasException") .condition("java.lang.String") .build(); assertThatThrownBy(() -> testee.init(matcherConfig)).isInstanceOf(MessagingException.class); }
@Test public void initShouldRaiseMessagingExceptionWhenClassNameIsNotFullyQualified() throws MessagingException { mockedMail.setAttribute(new Attribute(Mail.MAILET_ERROR, AttributeValue.ofSerializable(new javax.mail.MessagingException()))); FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("HasException") .condition("MessagingException") .build(); assertThatThrownBy(() -> testee.init(matcherConfig)).isInstanceOf(MessagingException.class); }