RemoteAddrInNetwork extends AbstractNetworkMatcher { @Override public Collection<MailAddress> match(Mail mail) { if (matchNetwork(mail.getRemoteAddr())) { return mail.getRecipients(); } return null; }  @Override Collection<MailAddress> match(Mail mail);  }
@Test public void shouldMatchWhenOnSameNetwork() throws MessagingException { fakeMail = FakeMail.builder() .name("name") .recipient(testRecipient) .remoteAddr("192.168.200.1") .build(); Collection<MailAddress> actual = matcher.match(fakeMail); assertThat(actual).containsOnly(testRecipient); }
@Test public void shouldNotMatchWhenOnDifferentNetwork() throws MessagingException { fakeMail = FakeMail.builder() .name("name") .recipient(testRecipient) .remoteAddr("192.168.1.1") .build(); Collection<MailAddress> actual = matcher.match(fakeMail); assertThat(actual).isNull(); }
@Test public void shouldNotMatchWhenNoCondition() throws MessagingException { FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("") .build(); RemoteAddrInNetwork testee = new RemoteAddrInNetwork(); testee.init(matcherConfig); fakeMail = FakeMail.builder() .name("name") .recipient(testRecipient) .build(); Collection<MailAddress> actual = testee.match(fakeMail); assertThat(actual).isNull(); }
@Test public void shouldNotMatchWhenInvalidAddress() throws MessagingException { fakeMail = FakeMail.builder() .name("name") .recipient(testRecipient) .remoteAddr("invalid") .build(); Collection<MailAddress> actual = matcher.match(fakeMail); assertThat(actual).isNull(); }