public void testMatchesBeanWithoutInfoWithMatchedNamedProperty() { final Matcher<BeanWithoutInfo> propertyMatcher = hasProperty("property", equalTo("is expected")); assertMatches("with property", propertyMatcher, shouldMatch); assertMismatchDescription("property 'property' was \"not expected\"", propertyMatcher, shouldNotMatch); }
public void testMatchesBeanWithoutInfoWithMatchedNamedBooleanProperty() { final Matcher<BeanWithoutInfo> booleanPropertyMatcher = hasProperty("booleanProperty", is(true)); assertMatches("with property", booleanPropertyMatcher, shouldMatch); assertMismatchDescription("property 'booleanProperty' was <false>", booleanPropertyMatcher, shouldNotMatch); }
public void testMatchesBeanWithInfoWithMatchedNamedProperty() { assertMatches("with bean info", hasProperty("property", equalTo("with info")), beanWithInfo); assertMismatchDescription("property 'property' was \"with info\"", hasProperty("property", equalTo("without info")), beanWithInfo); }
public void testDoesNotMatchWriteOnlyProperty() { assertMismatchDescription("property \"writeOnlyProperty\" is not readable", hasProperty("writeOnlyProperty", anything()), shouldNotMatch); }
public void testDoesNotMatchBeanWithoutInfoOrMatchedNamedProperty() { assertMismatchDescription("No property \"nonExistentProperty\"", hasProperty("nonExistentProperty", anything()), shouldNotMatch); }
public void testDescribesMissingPropertyMismatch() { assertMismatchDescription("No property \"honk\"", hasProperty("honk", anything()), shouldNotMatch); }
public void testExceptionsInBeanMethodsShouldBeReportedCorrectly() { assertMismatchDescription( "Calling 'public java.lang.String org.hamcrest.beans.HasPropertyWithValueTest$BeanWithBug.getBroken()': \"bean failed\"", hasProperty("broken", anything()), new BeanWithBug()); }
public void testMatchesPath() { assertMatches("1-step path", hasPropertyAtPath("property", equalTo("is expected")), shouldMatch); assertMatches("2-step path", hasPropertyAtPath("inner.property", equalTo("is expected")), new BeanWithInner(shouldMatch)); assertMatches("3-step path", hasPropertyAtPath("inner.inner.property", equalTo("is expected")), new BeanWithInner(new BeanWithInner(shouldMatch))); assertMismatchDescription("inner.No property \"wrong\"", hasPropertyAtPath("inner.wrong.property", anything()), new BeanWithInner(new BeanWithInner(shouldMatch))); assertMismatchDescription("inner.inner.property.was \"not expected\"", hasPropertyAtPath("inner.inner.property", equalTo("something")), new BeanWithInner(new BeanWithInner(shouldNotMatch))); }