Package org.faktorips.testsupport
Class IpsMatchers
java.lang.Object
org.faktorips.testsupport.IpsMatchers
Hamcrest
Matchers for use in JUnit tests of Faktor-IPS (generated) code.-
Method Summary
Modifier and TypeMethodDescriptionstatic MessageListMessageMatcherCreates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith theSeverity.ERROR.static org.hamcrest.Matcher<org.faktorips.runtime.MessageList>Creates aMatcherthat matches aMessageListif it is notempty.static org.hamcrest.Matcher<org.faktorips.runtime.MessageList>Creates aMessageListMessageMatcherthat matches aMessageListif it contains noMessagewith theSeverity.ERROR.static MessageMatchercontainsText(String text) static MessageListMessageMatcherhasErrorMessage(String code) Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.ERROR.static <T,U> org.hamcrest.FeatureMatcher<T, U> hasFeature(Function<T, U> featureExtractor, org.hamcrest.Matcher<U> featureMatcher, String featureDescription, String featureName) Creates aFeatureMatcherthat extracts a<U>feature from a<T>object and matches it with the given matcher.static MessageListMessageMatcherhasInfoMessage(String code) Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.INFO.static MessageMatcherhasInvalidObject(Object invalidObject) static MessageMatcherhasInvalidObject(Object invalidObject, String propertyName) static MessageMatcherhasMarker(org.faktorips.runtime.IMarker marker) static org.hamcrest.Matcher<org.faktorips.runtime.MessageList>hasMessageCode(String code) Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencode.static MessageMatcherhasMessageCodeThat(org.hamcrest.Matcher<String> messageCodeMatcher) hasMessageFor(Object object) Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactly oneMessagewith anObjectPropertyfor the given object.hasMessageFor(Object object, String property) Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactly oneMessagewith anObjectPropertyfor the given object's given property.static org.hamcrest.Matcher<org.faktorips.runtime.MessageList>hasMessages(org.hamcrest.Matcher<org.faktorips.runtime.Message>... messageMatchers) AMatcherthat matches if, for every givenMatcher, the checkedMessageListcontains aMessagethat is matched by thatMatcher.hasMessagesFor(int count, Object object, String property) Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactlycountMessageswith anObjectPropertyfor the given object's given property.static MessageListMessageMatcherhasMessageThat(MessageMatcher messageMatcher) Creates aMatcherthat matches if anyMessagein theMessageListis matched by the givenMatcher.static MessageListMessageMatcherhasMessageWithSeverity(org.faktorips.runtime.Severity severity) Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givenSeverity.static <P> MessageMatcherhasProperty(Function<org.faktorips.runtime.Message, P> propertyExtractor, org.hamcrest.Matcher<P> propertyMatcher, String propertyDescription) Creates aMessageMatcherthat extracts a<P>property from aMessageand matches it with the given matcher.static MessageMatcherhasSeverity(org.faktorips.runtime.Severity severity) static MessageListSizeMatcherhasSize(int size) static MessageListSizeMatcherCreates aMessageListSizeMatcherthat matches aMessageListif it'ssizeis matched by the givenMatcher<Integer>.static MessageListMessageMatcherhasWarningMessage(String code) Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.WARNING.static EmptyMessageListMatcherisEmpty()static org.hamcrest.Matcher<org.faktorips.runtime.MessageList>lacksMessageCode(String code) Creates aMessageListMessageMatcherthat matches aMessageListif it contains noMessagewith the givencode.
-
Method Details
-
isEmpty
-
containsMessages
public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> containsMessages()Creates aMatcherthat matches aMessageListif it is notempty. -
hasSize
- Parameters:
size- the expected size
-
hasSize
Creates aMessageListSizeMatcherthat matches aMessageListif it'ssizeis matched by the givenMatcher<Integer>.- Parameters:
intMatcher- theMatcher<Integer>for the size
-
hasMessageFor
Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactly oneMessagewith anObjectPropertyfor the given object.- Parameters:
object- the expected object
-
hasMessageFor
Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactly oneMessagewith anObjectPropertyfor the given object's given property.- Parameters:
object- the expected objectproperty- the expected object property
-
hasMessagesFor
public static MessageListObjectPropertyMatcher hasMessagesFor(int count, Object object, String property) Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactlycountMessageswith anObjectPropertyfor the given object's given property.- Parameters:
object- the expected objectproperty- the expected object propertycount- the expected number of messages for the given object property
-
hasMessageCode
Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencode.- Parameters:
code- the expected message code
-
lacksMessageCode
Creates aMessageListMessageMatcherthat matches aMessageListif it contains noMessagewith the givencode.- Parameters:
code- the message code
-
hasInfoMessage
Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.INFO.- Parameters:
code- the expected message code
-
hasWarningMessage
Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.WARNING.- Parameters:
code- the expected message code
-
hasErrorMessage
Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.ERROR.- Parameters:
code- the expected message code
-
hasMessageWithSeverity
public static MessageListMessageMatcher hasMessageWithSeverity(org.faktorips.runtime.Severity severity) Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givenSeverity.- Parameters:
severity- the expectedSeverity
-
containsErrorMessage
Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith theSeverity.ERROR. -
containsNoErrorMessage
public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> containsNoErrorMessage()Creates aMessageListMessageMatcherthat matches aMessageListif it contains noMessagewith theSeverity.ERROR. -
hasMessageThat
Creates aMatcherthat matches if anyMessagein theMessageListis matched by the givenMatcher.- Parameters:
messageMatcher- aMatcherfor a singleMessage
-
hasMessages
@SafeVarargs public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> hasMessages(org.hamcrest.Matcher<org.faktorips.runtime.Message>... messageMatchers) AMatcherthat matches if, for every givenMatcher, the checkedMessageListcontains aMessagethat is matched by thatMatcher. This must be a differentMessagefor everyMatchers. TheMessageListmay contain additionalMessagesnot matched by anyMatcher. The order of theMessagesandMatchersis irrelevant. -
containsText
- Parameters:
text- the text to match
-
hasSeverity
-
hasInvalidObject
-
hasInvalidObject
-
hasMessageCodeThat
-
hasMarker
-
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 aFeatureMatcherthat extracts a<U>feature from a<T>object and matches it with the given matcher.- Type Parameters:
T- the object type to matchU- the feature type to match- Parameters:
featureExtractor- the function to get the feature from the objectfeatureMatcher- the matcher for the featurefeatureDescription- 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 matcherfeatureName- 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 aMessageMatcherthat extracts a<P>property from aMessageand matches it with the given matcher.- Type Parameters:
P- the property type to match- Parameters:
propertyExtractor- the function to get the property from the objectpropertyMatcher- the matcher for the propertypropertyDescription- 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
-