And extends GenericCompositeMatcher { @Override public Collection<MailAddress> match(final Mail mail) throws MessagingException { ImmutableList<Set<MailAddress>> individualMatchedResults = performMatchOnMatchers(mail); return computeIntersection(individualMatchedResults); }  @Override Collection<MailAddress> match(final Mail mail);  }
@Test public void shouldNotMatchWhenNoChild() throws Exception { assertThat(testee.match(mail)).isEmpty(); }
@Test public void shouldMatchWhenSingleUnderlyingMatcherMatch() throws Exception { when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES)); testee.add(matcher1); assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES); }
@Test public void shouldMatchWhenTwoUnderlyingMatcherMatch() throws Exception { when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES)); when(matcher2.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2)); testee.add(matcher1); testee.add(matcher2); assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES); }
@Test public void shouldMatchWhenAtLeastOneUnderlyingMatcherDoNotMatch() throws Exception { when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES)); when(matcher2.match(mail)).thenReturn(ImmutableList.<MailAddress>of()); testee.add(matcher1); testee.add(matcher2); assertThat(testee.match(mail)).isEmpty(); }
@Test public void shouldSupportNull() throws Exception { when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES)); when(matcher2.match(mail)).thenReturn(null); testee.add(matcher1); testee.add(matcher2); assertThat(testee.match(mail)).isEmpty(); }