Package org.hamcrest.beans
Class SamePropertyValuesAs<T>
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.DiagnosingMatcher<T>
org.hamcrest.beans.SamePropertyValuesAs<T>
- All Implemented Interfaces:
Matcher<T>
,SelfDescribing
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final T
private final List<SamePropertyValuesAs.PropertyMatcher>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
describeTo
(Description description) 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) private static <T> List<SamePropertyValuesAs.PropertyMatcher>
propertyMatchersFor
(T bean, PropertyDescriptor[] descriptors, List<String> ignoredFields) propertyNamesFrom
(PropertyDescriptor[] descriptors, List<String> ignoredFields) private static Object
readProperty
(Method method, Object target) 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.Methods inherited from class org.hamcrest.DiagnosingMatcher
describeMismatch, matches
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
-
Field Details
-
expectedBean
-
propertyNames
-
propertyMatchers
-
ignoredFields
-
-
Constructor Details
-
SamePropertyValuesAs
-
-
Method Details
-
matches
- Specified by:
matches
in classDiagnosingMatcher<T>
-
describeTo
Description copied from interface:SelfDescribing
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
- The description to be built or appended to.
-
isCompatibleType
-
hasNoExtraProperties
-
hasMatchingValues
-
propertyMatchersFor
private static <T> List<SamePropertyValuesAs.PropertyMatcher> propertyMatchersFor(T bean, PropertyDescriptor[] descriptors, List<String> ignoredFields) -
propertyNamesFrom
private static Set<String> propertyNamesFrom(PropertyDescriptor[] descriptors, List<String> ignoredFields) -
isIgnored
-
readProperty
-
samePropertyValuesAs
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 exampleage
rather than method names such asgetAge
. For example:assertThat(myBean, samePropertyValuesAs(myExpectedBean))
assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height")
- Parameters:
expectedBean
- the bean against which examined beans are comparedignoredProperties
- do not check any of these named properties.
-