Contact Us 1-800-596-4880

MUnit Iterable and Map Matchers Reference

logo acb active Anypoint Code Builder

logo studio active Anypoint Studio

MUnit Iterable and Map matchers are matcher functions for asserting conditions on collections and maps during a MUnit test. Use them with the Assert That processor to check items, keys, values, and sizes of iterables and maps.

everyItem(Matcher)

Checks that every element in the expression matches the specified matcher.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::everyItem(MunitTools::notNullValue())]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::everyItem(MunitTools::startsWith('a'))]"/>

hasItem(Object)

Checks that any element in the expression matches the specified matcher.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::hasItem('example')]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::hasItem(MunitTools::startsWith('a'))]"/>

hasSize(Matcher|Integer)

Checks that the size of the expression matches the specified matcher.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::hasSize(MunitTools::greaterThan(2))]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::hasSize(5)]"/>

isEmpty()

Checks that the expression is an empty collection.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::isEmpty()]"/>

hasKey(Matcher|String)

Checks that the expression has a key that matches the specified matcher.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::hasKey(MunitTools::startsWith('a'))]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::hasKey('mykey')]"/>

hasValue(Object)

Checks that the expression has a value that matches the specified matcher.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::hasValue('myvalue')]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::hasValue(MunitTools::startsWith('a'))]"/>