Class IpsMatchers

java.lang.Object
org.faktorips.testsupport.IpsMatchers

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

    • isEmpty

      public static EmptyMessageListMatcher isEmpty()
      Creates an EmptyMessageListMatcher that matches a MessageList if it is empty.
    • 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(int size)
      Creates a MessageListSizeMatcher that matches a MessageList if it's size equal to the given size.
      Parameters:
      size - the expected size
    • hasSize

      public static MessageListSizeMatcher hasSize(org.hamcrest.Matcher<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(Object object)
      Creates a MessageListObjectPropertyMatcher that matches a MessageList if it contains exactly one Message with an ObjectProperty for the given object.
      Parameters:
      object - the expected object
    • hasMessageFor

      public static MessageListObjectPropertyMatcher hasMessageFor(Object object, 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, Object object, 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(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(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(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(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(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
    • containsErrorMessage

      public static MessageListMessageMatcher containsErrorMessage()
      Creates a MessageListMessageMatcher that matches a MessageList if it contains at least one Message with the Severity.ERROR.
    • 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(MessageMatcher 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 MessageMatcher containsText(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 MessageMatcher hasSeverity(org.faktorips.runtime.Severity severity)
    • hasInvalidObject

      public static MessageMatcher hasInvalidObject(Object invalidObject)
    • hasInvalidObject

      public static MessageMatcher hasInvalidObject(Object invalidObject, String propertyName)
    • hasMessageCodeThat

      public static MessageMatcher hasMessageCodeThat(org.hamcrest.Matcher<String> messageCodeMatcher)
    • hasMarker

      public static MessageMatcher hasMarker(org.faktorips.runtime.IMarker marker)
    • hasFeature

      public static <T, U> org.hamcrest.FeatureMatcher<T,U> hasFeature(Function<T,U> featureExtractor, org.hamcrest.Matcher<U> featureMatcher, String featureDescription, 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
    • hasProperty

      public static <P> MessageMatcher hasProperty(Function<org.faktorips.runtime.Message,P> propertyExtractor, org.hamcrest.Matcher<P> propertyMatcher, String propertyDescription)
      Creates a MessageMatcher that extracts a &lt;P&gt; property from a Message and matches it with the given matcher.
      Type Parameters:
      P - the property type to match
      Parameters:
      propertyExtractor - the function to get the property from the object
      propertyMatcher - the matcher for the property
      propertyDescription - the description of the object and property (e.g. "a car where the color is") that will be combined with the description of the given matcher
      Returns:
      a FeatureMatcher
      Since:
      22.6