@Test public void should_fail_if_match_is_not_successful() { BeanFieldMatcher matcher = new BeanPropertyMatcher("firstName", is("Bill")); Person person = new Person("Graeam", "Garden"); assertThat(matcher.matches(person)).isFalse(); }
@Test public void should_match_field_by_name() { BeanFieldMatcher matcher = new BeanPropertyMatcher("firstName", is("Bill")); Person person = new Person("Bill", "Oddie"); assertThat(matcher.matches(person)).isTrue(); }
@Test public void should_match_date_fields() { Person bill = new Person("Bill", "Oddie", new DateTime(1950, 1, 1, 12, 1)); BeanFieldMatcher birthdayAfter1900 = new BeanPropertyMatcher("birthday", isAfter(new DateTime(1900, 1, 1, 1, 0))); assertThat(birthdayAfter1900.matches(bill)).isTrue(); }
@Test public void should_match_number_fields() { Person bill = new Person("Bill", "Oddie", new DateTime(1950, 1, 1, 12, 1), new BigDecimal("42.1")); BeanFieldMatcher favoriteNumberIsNot42 = new BeanPropertyMatcher("favoriteNumber", greaterThan(new BigDecimal("42"))); assertThat(favoriteNumberIsNot42.matches(bill)).isTrue(); }
@Test public void should_obtain_matcher_from_fluent_static_method() { BeanFieldMatcher matcher = (BeanFieldMatcher) BeanMatchers.the("firstName", is("Bill")); Person person = new Person("Bill", "Oddie"); assertThat(matcher.matches(person)).isTrue(); }