Class IpsMatchers


  • public class IpsMatchers
    extends java.lang.Object
    Hamcrest Matchers for use in JUnit tests of Faktor-IPS (generated) code.
    • Method Detail

      • containsMessages

        public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> containsMessages()
        Creates a Matcher that matches a MessageList if it is not empty.
      • hasSize

        public static MessageListSizeMatcher hasSize​(org.hamcrest.Matcher<java.lang.Integer> intMatcher)
        Creates a MessageListSizeMatcher that matches a MessageList if it's size is matched by the given Matcher<Integer>.
        Parameters:
        intMatcher - the Matcher<Integer> for the size
      • hasMessageFor

        public static MessageListObjectPropertyMatcher hasMessageFor​(java.lang.Object object,
                                                                     java.lang.String property)
        Creates a MessageListObjectPropertyMatcher that matches a MessageList if it contains exactly one Message with an ObjectProperty for the given object's given property.
        Parameters:
        object - the expected object
        property - the expected object property
      • hasMessagesFor

        public static MessageListObjectPropertyMatcher hasMessagesFor​(int count,
                                                                      java.lang.Object object,
                                                                      java.lang.String property)
        Creates a MessageListObjectPropertyMatcher that matches a MessageList if it contains exactly count Messages with an ObjectProperty for the given object's given property.
        Parameters:
        object - the expected object
        property - the expected object property
        count - the expected number of messages for the given object property
      • hasMessageCode

        public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> hasMessageCode​(java.lang.String code)
        Creates a MessageListMessageMatcher that matches a MessageList if it contains at least one Message with the given code.
        Parameters:
        code - the expected message code
      • lacksMessageCode

        public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> lacksMessageCode​(java.lang.String code)
        Creates a MessageListMessageMatcher that matches a MessageList if it contains no Message with the given code.
        Parameters:
        code - the message code
      • hasInfoMessage

        public static MessageListMessageMatcher hasInfoMessage​(java.lang.String code)
        Creates a MessageListMessageMatcher that matches a MessageList if it contains at least one Message with the given code and Severity.INFO.
        Parameters:
        code - the expected message code
      • hasWarningMessage

        public static MessageListMessageMatcher hasWarningMessage​(java.lang.String code)
        Creates a MessageListMessageMatcher that matches a MessageList if it contains at least one Message with the given code and Severity.WARNING.
        Parameters:
        code - the expected message code
      • hasErrorMessage

        public static MessageListMessageMatcher hasErrorMessage​(java.lang.String code)
        Creates a MessageListMessageMatcher that matches a MessageList if it contains at least one Message with the given code and Severity.ERROR.
        Parameters:
        code - the expected message code
      • hasMessageWithSeverity

        public static MessageListMessageMatcher hasMessageWithSeverity​(org.faktorips.runtime.Severity severity)
        Creates a MessageListMessageMatcher that matches a MessageList if it contains at least one Message with the given Severity.
        Parameters:
        severity - the expected Severity
      • containsNoErrorMessage

        public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> containsNoErrorMessage()
        Creates a MessageListMessageMatcher that matches a MessageList if it contains no Message with the Severity.ERROR.
      • hasMessageThat

        public static MessageListMessageMatcher hasMessageThat​(org.hamcrest.Matcher<org.faktorips.runtime.Message> messageMatcher)
        Creates a Matcher that matches if any Message in the MessageList is matched by the given Matcher.
        Parameters:
        messageMatcher - a Matcher for a single Message
      • hasMessages

        @SafeVarargs
        public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> hasMessages​(org.hamcrest.Matcher<org.faktorips.runtime.Message>... messageMatchers)
        A Matcher that matches if, for every given Matcher, the checked MessageList contains a Message that is matched by that Matcher. This must be a different Message for every Matchers. The MessageList may contain additional Messages not matched by any Matcher. The order of the Messages and Matchers is irrelevant.
      • containsText

        public static org.hamcrest.Matcher<org.faktorips.runtime.Message> containsText​(java.lang.String text)
        Creates a Matcher that matches if the Message's text contains the given text.
        Parameters:
        text - the text to match
      • hasSeverity

        public static org.hamcrest.Matcher<org.faktorips.runtime.Message> hasSeverity​(org.faktorips.runtime.Severity severity)
      • hasInvalidObject

        public static org.hamcrest.Matcher<org.faktorips.runtime.Message> hasInvalidObject​(java.lang.Object invalidObject)
      • hasInvalidObject

        public static org.hamcrest.Matcher<org.faktorips.runtime.Message> hasInvalidObject​(java.lang.Object invalidObject,
                                                                                           java.lang.String propertyName)
      • hasFeature

        public static <T,​U> org.hamcrest.FeatureMatcher<T,​U> hasFeature​(java.util.function.Function<T,​U> featureExtractor,
                                                                                    org.hamcrest.Matcher<U> featureMatcher,
                                                                                    java.lang.String featureDescription,
                                                                                    java.lang.String featureName)
        Creates a FeatureMatcher that extracts a &lt;U&gt; feature from a &lt;T&gt; object and matches it with the given matcher.
        Type Parameters:
        T - the object type to match
        U - the feature type to match
        Parameters:
        featureExtractor - the function to get the feature from the object
        featureMatcher - the matcher for the feature
        featureDescription - the description of the object and feature (e.g. "a car where the color is") that will be combined with the description of the given matcher
        featureName - the name of the feature
        Returns:
        a FeatureMatcher