Top Inners Fields Constructors Methods
org.hamcrest.beans

public Class SamePropertyValuesAs<T>

extends DiagnosingMatcher<T>
Class Inheritance
Imports
org.hamcrest.Description, .DiagnosingMatcher, .Matcher, java.beans.PropertyDescriptor, java.lang.reflect.Method, java.util.*

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final T
private final List<String>
private final List<SamePropertyValuesAs.PropertyMatcher>
private final Set<String>

Constructor Summary

AccessConstructor and Description
public
SamePropertyValuesAs(T expectedBean, List<String> ignoredProperties)

Method Summary

Modifier and TypeMethod and Description
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
private boolean
hasMatchingValues(Object actual, Description mismatchDescription)

private boolean
hasNoExtraProperties(Object actual, Description mismatchDescription)

private boolean
isCompatibleType(Object actual, Description mismatchDescription)

private static boolean
isIgnored(List<String> ignoredFields, PropertyDescriptor propertyDescriptor)

protected boolean
matches(Object actual, Description mismatch)

Implements abstract org.hamcrest.DiagnosingMatcher.matches.

private static <T> List<SamePropertyValuesAs.PropertyMatcher>
propertyMatchersFor(T bean, PropertyDescriptor[] descriptors, List<String> ignoredFields)

private static Set<String>
propertyNamesFrom(PropertyDescriptor[] descriptors, List<String> ignoredFields)

private static Object
readProperty(Method method, Object target)

public static <B> Matcher<B>
samePropertyValuesAs(B
the bean against which examined beans are compared
expectedBean
,
String...
do not check any of these named properties.
ignoredProperties
)

Creates a matcher that matches when the examined object has values for all of its JavaBean properties that are equal to the corresponding values of the specified bean.

Inherited from org.hamcrest.DiagnosingMatcher:
describeMismatchmatches

Field Detail

expectedBeanback to summary
private final T expectedBean
ignoredFieldsback to summary
private final List<String> ignoredFields
propertyMatchersback to summary
private final List<SamePropertyValuesAs.PropertyMatcher> propertyMatchers
propertyNamesback to summary
private final Set<String> propertyNames

Constructor Detail

SamePropertyValuesAsback to summary
public SamePropertyValuesAs(T expectedBean, List<String> ignoredProperties)
Annotations
@SuppressWarnings:WeakerAccess

Method Detail

describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
hasMatchingValuesback to summary
private boolean hasMatchingValues(Object actual, Description mismatchDescription)
hasNoExtraPropertiesback to summary
private boolean hasNoExtraProperties(Object actual, Description mismatchDescription)
isCompatibleTypeback to summary
private boolean isCompatibleType(Object actual, Description mismatchDescription)
isIgnoredback to summary
private static boolean isIgnored(List<String> ignoredFields, PropertyDescriptor propertyDescriptor)
matchesback to summary
protected boolean matches(Object actual, Description mismatch)

Implements abstract org.hamcrest.DiagnosingMatcher.matches.

Annotations
@Override
propertyMatchersForback to summary
private static <T> List<SamePropertyValuesAs.PropertyMatcher> propertyMatchersFor(T bean, PropertyDescriptor[] descriptors, List<String> ignoredFields)
propertyNamesFromback to summary
private static Set<String> propertyNamesFrom(PropertyDescriptor[] descriptors, List<String> ignoredFields)
readPropertyback to summary
private static Object readProperty(Method method, Object target)
samePropertyValuesAsback to summary
public static <B> Matcher<B> samePropertyValuesAs(B expectedBean, String... ignoredProperties)

Creates a matcher that matches when the examined object has values for all of its JavaBean properties that are equal to the corresponding values of the specified bean. If any properties are marked as ignored, they will be dropped from both the expected and actual bean. Note that the ignored properties use JavaBean display names, for example

age
rather than method names such as
getAge
. For example:
assertThat(myBean, samePropertyValuesAs(myExpectedBean))
assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height")
Parameters
expectedBean:B

the bean against which examined beans are compared

ignoredProperties:String[]

do not check any of these named properties.

org.hamcrest.beans back to summary

private Class SamePropertyValuesAs.PropertyMatcher

extends DiagnosingMatcher<Object>
Class Inheritance
Annotations
@SuppressWarnings:WeakerAccess

Field Summary

Modifier and TypeField and Description
private final Matcher<Object>
private final String
private final Method

Constructor Summary

AccessConstructor and Description
public
PropertyMatcher(PropertyDescriptor descriptor, Object expectedObject)

Method Summary

Modifier and TypeMethod and Description
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public boolean
matches(Object actual, Description mismatch)

Implements abstract org.hamcrest.DiagnosingMatcher.matches.

Inherited from org.hamcrest.DiagnosingMatcher:
describeMismatchmatches

Field Detail

matcherback to summary
private final Matcher<Object> matcher
propertyNameback to summary
private final String propertyName
readMethodback to summary
private final Method readMethod

Constructor Detail

PropertyMatcherback to summary
public PropertyMatcher(PropertyDescriptor descriptor, Object expectedObject)

Method Detail

describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
matchesback to summary
public boolean matches(Object actual, Description mismatch)

Implements abstract org.hamcrest.DiagnosingMatcher.matches.

Annotations
@Override