Nav
You are viewing an older version of this topic. To go to a different version, use the version menu at the upper-right. +

About MUnit Matchers

MUnit matchers are a set of DataWeave functions to define mocks, verifications, and assertions conditions in terms of general values rather than specific hardcoded values.

When defining matchers you need to add the MuniTools:: prefix to the expression.
A matcher does not receive parameters; rather, it’s a parameter itself that you can use to validate the result of an expression.

Table 1. MUnit Matcher Functions
Matcher Name Description Example

nullValue()

Checks that the expression is null

#[MunitTools::nullValue()]

notNullValue()

Checks that the expression is null

#[MunitTools::notNullValue()]

equalTo(Object)

Checks that the expression is equal to a specific value

#[MunitTools::equalTo(0)]
#[MunitTools::equalTo(‘example’)]

not(Matcher)

Checks if the provided matcher is not successful

#[MunitTools::not(MunitTools::equalTo(0))]

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))]

In this topic: