コード例 #1
1
  @Test
  public void should_return_matching_element() {
    Map<String, String> bill = mappedPerson("Bill", "Oddie");
    Map<String, String> graham = mappedPerson("Graeam", "Garden");
    Map<String, String> tim = mappedPerson("Tim", "Brooke-Taylor");
    List<Map<String, String>> persons = Arrays.asList(bill, graham, tim);

    BeanMatcher firstNameIsBill = BeanMatchers.the("firstName", is("Bill"));
    BeanMatcher lastNameIsOddie = BeanMatchers.the("lastName", is("Oddie"));

    assertThat(BeanMatcherAsserts.filterElements(persons, firstNameIsBill, lastNameIsOddie))
        .contains(bill);
  }
コード例 #2
0
  @Test
  public void should_return_no_elements_if_no_matching_elements_found() {
    Map<String, String> billoddie = mappedPerson("Bill", "Oddie");
    Map<String, String> billkidd = mappedPerson("Bill", "Kidd");
    Map<String, String> graham = mappedPerson("Graeam", "Garden");
    Map<String, String> tim = mappedPerson("Tim", "Brooke-Taylor");
    List<Map<String, String>> persons = Arrays.asList(billoddie, billkidd, graham, tim);

    BeanMatcher firstNameIsJoe = BeanMatchers.the("firstName", is("Joe"));

    assertThat(BeanMatcherAsserts.filterElements(persons, firstNameIsJoe)).isEmpty();
  }