MUNIT MATCHERS
Shanky Gupta
OVERVIEW
MUnit matchers are a set of MEL functions that help in the creation of mocks
and validations (verifications/assertions). They enable you to define mocks,
verifications and assertions in terms of general values rather than specific
hardcoded values.
A matcher is a boolean function. In most of the MUnit matchers, this function
is a class type comparison. Its purpose is to validate if an argument belongs
to a certain class type.
A matcher does not receive parameters; rather, it’s a parameter itself.
isNull()
• Matches if the evaluated object is Null.
isNotNull()
• Matches if the evaluated object is not Null.
anyObject()
• Matches if the evaluated object is an Object.
anyBoolean()
• Matches if the evaluated object is a Boolean.
anyByte()
anyByteArray()
• Matches if the evaluated object is a Byte.
• Matches if the evaluated object is a ByteArray.
anyInt()
anyDouble()
• Matches if the evaluated object is a Double.
• Matches if the evaluated object is an Integer.
anyFloat()
anyShort()
• Matches if the evaluated object is a Short.
• Matches if the evaluated object is a Float.
anyString()
anyCollection()
• Matches if the evaluated object is a Collection.
• Matches if the evaluated object is a String.
anyList()
anySet()
anyMap()
• Matches if the evaluated object is a List.
• Matches if the evaluated object is a Set.
• Matches if the evaluated object is a Map.
…MATCHER FUNCTIONS CONTINUED
MUnit also offers some additional, rather specific, type of matchers. These
matchers evaluate thecontent of the parameter, not its type; even so, they do
not evaluate by specific values.
matchRegex(<regex>)
matchContains(<string_to_look_for>)
• Matches if the value of the attribute during the test run verifies the user-provided
regular expression
• Matches if the value of the attribute during the test run contains the specified user-
provided string.
USAGE INSTRUCTION
• MUnit matchers are always used in combination with the Mocks, Spy, Verify and
Assert message processors, but never on their own.
MUNIT MATCHERS OVER MULE
MESSAGE PROPERTIES
• If you wish to run assertions over Mule message properties and use MUnit matchers,
you can use the valueOf() function.
• To make it easier to write this type of assertions, MUnit offers a another set of MEL
functions that provide direct access for Mule message’s properties ElementMatcher.
messageInboundProperty(propertyName)
• Returns an ElementMatcher for the inbound property with the name
provided.
messageOutboundProperty(propertyName)
messageInvocationProperty(propertyName)
• Returns an ElementMatcher for the outbound property with the name
provided.
• Returns an ElementMatcher for the invocation property with the name
provided.
messageInboundAttachment(propertyName)
messageOutboundAttachment(propertyName)
• Returns an ElementMatcher for the inbound attachment with the name
provided.
• Returns an ElementMatcher for the outbound attachment with the name
provided.

MUnit matchers

  • 1.
  • 2.
    OVERVIEW MUnit matchers area set of MEL functions that help in the creation of mocks and validations (verifications/assertions). They enable you to define mocks, verifications and assertions in terms of general values rather than specific hardcoded values. A matcher is a boolean function. In most of the MUnit matchers, this function is a class type comparison. Its purpose is to validate if an argument belongs to a certain class type. A matcher does not receive parameters; rather, it’s a parameter itself.
  • 3.
    isNull() • Matches ifthe evaluated object is Null. isNotNull() • Matches if the evaluated object is not Null.
  • 4.
    anyObject() • Matches ifthe evaluated object is an Object. anyBoolean() • Matches if the evaluated object is a Boolean.
  • 5.
    anyByte() anyByteArray() • Matches ifthe evaluated object is a Byte. • Matches if the evaluated object is a ByteArray.
  • 6.
    anyInt() anyDouble() • Matches ifthe evaluated object is a Double. • Matches if the evaluated object is an Integer.
  • 7.
    anyFloat() anyShort() • Matches ifthe evaluated object is a Short. • Matches if the evaluated object is a Float.
  • 8.
    anyString() anyCollection() • Matches ifthe evaluated object is a Collection. • Matches if the evaluated object is a String.
  • 9.
    anyList() anySet() anyMap() • Matches ifthe evaluated object is a List. • Matches if the evaluated object is a Set. • Matches if the evaluated object is a Map.
  • 10.
    …MATCHER FUNCTIONS CONTINUED MUnitalso offers some additional, rather specific, type of matchers. These matchers evaluate thecontent of the parameter, not its type; even so, they do not evaluate by specific values. matchRegex(<regex>) matchContains(<string_to_look_for>) • Matches if the value of the attribute during the test run verifies the user-provided regular expression • Matches if the value of the attribute during the test run contains the specified user- provided string.
  • 11.
    USAGE INSTRUCTION • MUnitmatchers are always used in combination with the Mocks, Spy, Verify and Assert message processors, but never on their own.
  • 12.
    MUNIT MATCHERS OVERMULE MESSAGE PROPERTIES • If you wish to run assertions over Mule message properties and use MUnit matchers, you can use the valueOf() function. • To make it easier to write this type of assertions, MUnit offers a another set of MEL functions that provide direct access for Mule message’s properties ElementMatcher. messageInboundProperty(propertyName) • Returns an ElementMatcher for the inbound property with the name provided.
  • 13.
    messageOutboundProperty(propertyName) messageInvocationProperty(propertyName) • Returns anElementMatcher for the outbound property with the name provided. • Returns an ElementMatcher for the invocation property with the name provided.
  • 14.
    messageInboundAttachment(propertyName) messageOutboundAttachment(propertyName) • Returns anElementMatcher for the inbound attachment with the name provided. • Returns an ElementMatcher for the outbound attachment with the name provided.