Package org.faktorips.testsupport
Class IpsMatchers
- java.lang.Object
-
- org.faktorips.testsupport.IpsMatchers
-
public class IpsMatchers extends java.lang.ObjectHamcrestMatchersfor use in JUnit tests of Faktor-IPS (generated) code.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MessageListMessageMatchercontainsErrorMessage()Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith theSeverity.ERROR.static org.hamcrest.Matcher<org.faktorips.runtime.MessageList>containsMessages()Creates aMatcherthat matches aMessageListif it is notempty.static org.hamcrest.Matcher<org.faktorips.runtime.MessageList>containsNoErrorMessage()Creates aMessageListMessageMatcherthat matches aMessageListif it contains noMessagewith theSeverity.ERROR.static org.hamcrest.Matcher<org.faktorips.runtime.Message>containsText(java.lang.String text)Creates aMatcherthat matches if theMessage's textcontainsthe given text.static MessageListMessageMatcherhasErrorMessage(java.lang.String code)Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.ERROR.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 aFeatureMatcherthat extracts a<U>feature from a<T>object and matches it with the given matcher.static MessageListMessageMatcherhasInfoMessage(java.lang.String code)Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.INFO.static org.hamcrest.Matcher<org.faktorips.runtime.Message>hasInvalidObject(java.lang.Object invalidObject)static org.hamcrest.Matcher<org.faktorips.runtime.Message>hasInvalidObject(java.lang.Object invalidObject, java.lang.String propertyName)static org.hamcrest.Matcher<org.faktorips.runtime.MessageList>hasMessageCode(java.lang.String code)Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencode.static MessageListObjectPropertyMatcherhasMessageFor(java.lang.Object object)Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactly oneMessagewith anObjectPropertyfor the given object.static MessageListObjectPropertyMatcherhasMessageFor(java.lang.Object object, java.lang.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.static MessageListObjectPropertyMatcherhasMessagesFor(int count, java.lang.Object object, java.lang.String property)Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactlycountMessageswith anObjectPropertyfor the given object's given property.static MessageListMessageMatcherhasMessageThat(org.hamcrest.Matcher<org.faktorips.runtime.Message> 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 org.hamcrest.Matcher<org.faktorips.runtime.Message>hasSeverity(org.faktorips.runtime.Severity severity)static MessageListSizeMatcherhasSize(int size)static MessageListSizeMatcherhasSize(org.hamcrest.Matcher<java.lang.Integer> intMatcher)Creates aMessageListSizeMatcherthat matches aMessageListif it'ssizeis matched by the givenMatcher<Integer>.static MessageListMessageMatcherhasWarningMessage(java.lang.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(java.lang.String code)Creates aMessageListMessageMatcherthat matches aMessageListif it contains noMessagewith the givencode.
-
-
-
Method Detail
-
isEmpty
public static EmptyMessageListMatcher isEmpty()
-
containsMessages
public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> containsMessages()
Creates aMatcherthat matches aMessageListif it is notempty.
-
hasSize
public static MessageListSizeMatcher hasSize(int size)
- Parameters:
size- the expected size
-
hasSize
public static MessageListSizeMatcher hasSize(org.hamcrest.Matcher<java.lang.Integer> intMatcher)
Creates aMessageListSizeMatcherthat matches aMessageListif it'ssizeis matched by the givenMatcher<Integer>.- Parameters:
intMatcher- theMatcher<Integer>for the size
-
hasMessageFor
public static MessageListObjectPropertyMatcher hasMessageFor(java.lang.Object object)
Creates aMessageListObjectPropertyMatcherthat matches aMessageListif it contains exactly oneMessagewith anObjectPropertyfor the given object.- Parameters:
object- the expected object
-
hasMessageFor
public static MessageListObjectPropertyMatcher hasMessageFor(java.lang.Object object, java.lang.String property)
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, java.lang.Object object, java.lang.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
public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> hasMessageCode(java.lang.String code)
Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencode.- Parameters:
code- the expected message code
-
lacksMessageCode
public static org.hamcrest.Matcher<org.faktorips.runtime.MessageList> lacksMessageCode(java.lang.String code)
Creates aMessageListMessageMatcherthat matches aMessageListif it contains noMessagewith the givencode.- Parameters:
code- the message code
-
hasInfoMessage
public static MessageListMessageMatcher hasInfoMessage(java.lang.String code)
Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.INFO.- Parameters:
code- the expected message code
-
hasWarningMessage
public static MessageListMessageMatcher hasWarningMessage(java.lang.String code)
Creates aMessageListMessageMatcherthat matches aMessageListif it contains at least oneMessagewith the givencodeandSeverity.WARNING.- Parameters:
code- the expected message code
-
hasErrorMessage
public static MessageListMessageMatcher hasErrorMessage(java.lang.String code)
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
public static MessageListMessageMatcher 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
public static MessageListMessageMatcher hasMessageThat(org.hamcrest.Matcher<org.faktorips.runtime.Message> messageMatcher)
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
public static org.hamcrest.Matcher<org.faktorips.runtime.Message> containsText(java.lang.String text)
Creates aMatcherthat matches if theMessage's textcontainsthe 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 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
-
-