MUnit matches are a set of DataWeave functions to define assertion conditions for any value in an expression. When defining matches, include the prefix MunitTools:: in the expression.
Matchers are grouped according to the type of conditions you want to validate.
Matchers | Description | Example |
---|---|---|
nullValue() | Checks that the expression is null. | #[MunitTools::nullValue()] |
notNullValue() | Checks that the expression is not null. | #[MunitTools::notNullValue()] |
withMediaType(String) | Checks that the expression’s media type is the one specified. | #[MunitTools::withMediaType(‘text/xml’)] |
withEncoding(String) | Checks that the expression’s encoding is the one specified. | #[MunitTools::withEncoding(‘UTF-8’)] |
both(Matcher, Matcher) | Checks that both provided matchers are successful. | #[MunitTools::both(MunitTools::notNullValue(),MunitTools::equalTo(‘example’))] |
either(Matcher,Matcher) | Checks that at least one of the matchers is successful. | #[MunitTools::either(MunitTools::nullValue(),MunitTools::equalTo(0))] |
not(Object) | Checks if the provided matcher is not successful. | #[MunitTools::not(0)] |
anyOf(Array<Matcher>) | Checks if any of the matchers are successful. | #[MunitTools::anyOf([MunitTools::notNullValue(),MunitTools::withMediaType(‘text/xml’),MunitTools::isEmptyString()])] |
allOf(Array<Matcher>) | Checks if all of the matchers are successful. | #[MunitTools::allOf([MunitTools::notNullValue(),MunitTools::withMediaType(‘text/xml’),MunitTools::isEmptyString()])] |
Matchers | DescRiption | Example |
---|---|---|
containsString(String) | Checks that the expression contains the specified String. | #[MunitTools::containsString(‘example’)] |
startsWith(String) | Checks that the expression starts with the specified String. | #[MunitTools::startsWith(‘exam’)] |
endsWith(String) | Checks that the expression ends with the specified String. | #[MunitTools::endsWith(‘ple’)] |
isEmptyString() | Checks that the expression has zero length. | #[MunitTools::isEmptyString()] |
isEmptyOrNullString() | Checks that the expression is null, or has zero length. | #[MunitTools::isEmptyOrNullString()] |
equalToIgnoringCase(String) | Checks that the expression is equal to the specified String, ignoring case. | #[MunitTools::equalToIgnoringCase(‘example’)] |
equalToIgnoringWhiteSpace(String) | Checks that the expression is equal to the string disregarding leading and trailing white spaces, and compression all inner white spaces to a single space. | #[MunitTools::equalToIgnoringWhiteSpace(‘An Example’)] |
stringContainsInOrder(Array<String>) | Checks that the expression contains all of the specified substrings, regardless of the order of their appearance. | #[MunitTools::stringContainsInOrder([‘an’, ‘example’])] |
Matchers | description | example |
---|---|---|
greaterThan(Comparable) | Checks that the expression is greater than the specified value. | #[MunitTools::greaterThan(|2017-08-09|)] |
greaterThanOrEqualTo(Comparable) | Checks that the expression is greater than or equal to the specified value. | #[MunitTools::greaterThanOrEqualTo(20)] |
lessThan(Comparable) | Checks that the expression is less than to the specified value. | #[MunitTools::lessThanOrEqualTo(20)] |
closeTo(Number, Number) | Checks that the expression is close to the first number, using the second number as a delta value.In other words, checks that the expression belongs to the range defined by the first number +/- the second number. | #[MunitTools::closeTo(1, 0.01)] |
equalTo(Object) | Checks that the expression is equal to a specific value. | #[MunitTools::equalTo(0)] |
matchers | description | example |
---|---|---|
everyItem(Matcher) | Checks that every element in the expression matches the specified matcher. | #[MunitTools::everyItem(MunitTools::notNullValue())] |
hasItem(Object) | Checks that any element in the expression matches the specified matcher. | #[MunitTools::hasItem(‘example’)] |
hasSize(Matcher|Integer) | Checks that the size of the expression matches the specified matcher. | #[MunitTools::hasSize(MUnitTools::greaterThan(2))] |
isEmpty() | Checks that the expression is an empty collection. | #[MunitTools::isEmpty()] |
hasKey(Matcher|String) | Checks that the expression has a key that matches the specified matcher. | #[MunitTools::hasKey(MunitTools::startsWith(‘a’))] |
hasValue(Object) | Checks that the expression has a value that matches the specified matcher. | #[MunitTools::hasValue(MunitTools::startsWith(‘a’))] |
If you like my post please follow me to read my latest post on programming and technology.
You are given two singly linked lists that intersect at some node. Your task is…
A builder plans to construct N houses in a row, where each house can be…
Find the length of the longest absolute path to a file within the abstracted file…
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…