Fork me on GitHub

Testing the toString Method

Matchers for ensuring the bean class name and properties are included in toString output.

Ensure all properties on the bean are included in the string value.

assertThat(BeanToTest.class, hasValidBeanToString());

Ensure the string value includes includes the property named propertyInToString. Any other properties on the bean are not tested.

assertThat(BeanToTest.class, hasValidBeanToStringFor("propertyInToString"));

Ensure the string value includes all properties on the bean except the property named propertyNotInToString.

assertThat(BeanToTest.class, hasValidBeanToStringExcluding("propertyNotInToString"));