MUnit matchers
-
Upload
shanky-gupta -
Category
Technology
-
view
140 -
download
0
Transcript of MUnit matchers
![Page 1: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/1.jpg)
MUNIT MATCHERS
Shanky Gupta
![Page 2: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/2.jpg)
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.
![Page 3: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/3.jpg)
isNull()• Matches if the evaluated object is Null.
isNotNull()• Matches if the evaluated object is not Null.
![Page 4: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/4.jpg)
anyObject()• Matches if the evaluated object is an Object.
anyBoolean()• Matches if the evaluated object is a Boolean.
![Page 5: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/5.jpg)
anyByte()
anyByteArray()
• Matches if the evaluated object is a Byte.
• Matches if the evaluated object is a ByteArray.
![Page 6: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/6.jpg)
anyInt()
anyDouble()
• Matches if the evaluated object is a Double.
• Matches if the evaluated object is an Integer.
![Page 7: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/7.jpg)
anyFloat()
anyShort()• Matches if the evaluated object is a Short.
• Matches if the evaluated object is a Float.
![Page 8: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/8.jpg)
anyString()
anyCollection()• Matches if the evaluated object is a Collection.
• Matches if the evaluated object is a String.
![Page 9: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/9.jpg)
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.
![Page 10: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/10.jpg)
…MATCHER FUNCTIONS CONTINUEDMUnit 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.
![Page 11: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/11.jpg)
USAGE INSTRUCTION• MUnit matchers are always used in combination with the Mocks, Spy, Verify and Assert message processors, but never on their own.
![Page 12: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/12.jpg)
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.
![Page 13: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/13.jpg)
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.
![Page 14: MUnit matchers](https://reader033.fdocuments.in/reader033/viewer/2022042515/58a09d6b1a28ab9f758b59ad/html5/thumbnails/14.jpg)
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.