Top Inners Fields Constructors Methods
org.hamcrest.beans

public Class SamePropertyValuesAs<T>

extends TypeSafeDiagnosingMatcher<T>
Class Inheritance
Imports
org.hamcrest.*, java.beans.PropertyDescriptor, java.lang.reflect.Method, java.util.ArrayList, .HashSet, .List, .Set

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
SamePropertyValuesAs(T expectedBean)

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(T item, Description mismatchDescription)

private boolean
hasNoExtraProperties(T item, Description mismatchDescription)

private boolean
isCompatibleType(T item, Description mismatchDescription)

public boolean
matchesSafely(T bean, Description mismatch)

Implements abstract org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Subclasses should implement this.
private static <T> List<SamePropertyValuesAs.PropertyMatcher>
propertyMatchersFor(T bean, PropertyDescriptor[] descriptors)

private static Set<String>
private static Object
readProperty(Method method, Object target)

public static <T> Matcher<T>
samePropertyValuesAs(T
the bean against which examined beans are compared
expectedBean
)

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.TypeSafeDiagnosingMatcher:
describeMismatchmatches

Field Detail

expectedBeanback to summary
private final T expectedBean
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)

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(T item, Description mismatchDescription)
hasNoExtraPropertiesback to summary
private boolean hasNoExtraProperties(T item, Description mismatchDescription)
isCompatibleTypeback to summary
private boolean isCompatibleType(T item, Description mismatchDescription)
matchesSafelyback to summary
public boolean matchesSafely(T bean, Description mismatch)

Implements abstract org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.

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

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.

For example:

assertThat(myBean, samePropertyValuesAs(myExpectedBean))
Parameters
expectedBean:T

the bean against which examined beans are compared

Annotations
@Factory
org.hamcrest.beans back to summary

public Class SamePropertyValuesAs.PropertyMatcher

extends DiagnosingMatcher<Object>
Class Inheritance

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