Class SamePropertyValuesAs<T>

    • Field Detail

      • expectedBean

        private final T expectedBean
      • propertyNames

        private final java.util.Set<java.lang.String> propertyNames
      • ignoredFields

        private final java.util.List<java.lang.String> ignoredFields
    • Constructor Detail

      • SamePropertyValuesAs

        public SamePropertyValuesAs​(T expectedBean,
                                    java.util.List<java.lang.String> ignoredProperties)
    • Method Detail

      • describeTo

        public void describeTo​(Description description)
        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

        private boolean isCompatibleType​(java.lang.Object actual,
                                         Description mismatchDescription)
      • hasNoExtraProperties

        private boolean hasNoExtraProperties​(java.lang.Object actual,
                                             Description mismatchDescription)
      • hasMatchingValues

        private boolean hasMatchingValues​(java.lang.Object actual,
                                          Description mismatchDescription)
      • propertyMatchersFor

        private static <T> java.util.List<SamePropertyValuesAs.PropertyMatcher> propertyMatchersFor​(T bean,
                                                                                                    java.beans.PropertyDescriptor[] descriptors,
                                                                                                    java.util.List<java.lang.String> ignoredFields)
      • propertyNamesFrom

        private static java.util.Set<java.lang.String> propertyNamesFrom​(java.beans.PropertyDescriptor[] descriptors,
                                                                         java.util.List<java.lang.String> ignoredFields)
      • isIgnored

        private static boolean isIgnored​(java.util.List<java.lang.String> ignoredFields,
                                         java.beans.PropertyDescriptor propertyDescriptor)
      • readProperty

        private static java.lang.Object readProperty​(java.lang.reflect.Method method,
                                                     java.lang.Object target)
      • samePropertyValuesAs

        public static <B> Matcher<B> samePropertyValuesAs​(B expectedBean,
                                                          java.lang.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 - the bean against which examined beans are compared
        ignoredProperties - do not check any of these named properties.