---
schema_version: "1"
id: d34ef9d70c7f6e6e424f8e1a5d14e256dba8cb09cd8b473f5741e6ee6f572008
title: MUnit Matchers
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/latest/munit-matchers.md
canonical_url: https://docs.mulesoft.com/munit/latest/munit-matchers
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 09b0e344357583e39bf569c63b7a27c565e30ee29e44a447e6a23cc0f53a49ee
description: MuleSoft Documentation Site
release: "3.7"
latest: true
---
---
product: MUnit
version: 3.7
is-latest-version: true
keywords: munit, testing, unit testing
---

# MUnit Matchers

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

![logo acb active](/mulesoft/current/en-us/_/img/icons/anypoint-code-builder.svg "Anypoint Code Builder")Anypoint Code
Builder

![logo studio active](/mulesoft/current/en-us/_/img/icons/studio.svg "Anypoint Studio")Anypoint Studio

MUnit matchers are DataWeave functions that define assertion conditions for any value in an
expression, used with the Assert That processor. Include the prefix `MunitTools::` when using them,
and choose from core, string, comparable, or iterable and map matcher groups depending on the type
of value you want to validate.

## Match Core Values

Core matchers evaluate core values in the expression:

- Is the expression null?

- What is the media type or encoding of the expression?

- Does the expression return false?

- Are two evaluations successful?

Core Matchers:

- [nullValue()](https://docs.mulesoft.com/munit/latest/core-matchers-reference#nullvalue) checks that the expression is null.

  Example:

  ```DataWeave
  #[MunitTools::nullValue()]
  ```

- [notNullValue()](https://docs.mulesoft.com/munit/latest/core-matchers-reference#notnullvalue) checks that the expression is not null.

  Example:

  ```DataWeave
  #[MunitTools::notNullValue()]
  ```

- [withMediaType(String)](https://docs.mulesoft.com/munit/latest/core-matchers-reference#withmediatype-string) checks that the expression’s
  media type is the one specified.

  Example:

  ```DataWeave
  #[MunitTools::withMediaType('text/xml')]
  ```

- [withEncoding(String)](https://docs.mulesoft.com/munit/latest/core-matchers-reference#withencoding-string) checks that the expression’s
  encoding is the one specified.

  Example:

  ```DataWeave
  #[MunitTools::withEncoding('UTF-8')]
  ```

- [both(Matcher, Matcher)](https://docs.mulesoft.com/munit/latest/core-matchers-reference#both-matcher-matcher) checks that both provided
  matchers are successful.

  Example:

  ```DataWeave
  #[MunitTools::both(MunitTools::notNullValue(), MunitTools::equalTo('example'))]
  ```

- [either(Matcher,Matcher)](https://docs.mulesoft.com/munit/latest/core-matchers-reference#either-matcher-matcher) checks that at least one
  of the matchers is successful.

  Example:

  ```DataWeave
  #[MunitTools::either(MunitTools::nullValue(), MunitTools::equalTo(0))]
  ```

- [not(Matcher)](https://docs.mulesoft.com/munit/latest/core-matchers-reference#not-matcher) checks if the provided matcher is not
  successful.

  Example:

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

- [anyOf(Matchers\[\])](core-matchers-reference#anyof-matchers) checks if any of the matchers are
  successful.

  Example:

  ```DataWeave
  #[MunitTools::anyOf([MunitTools::notNullValue(),MunitTools::withMediaType('text/xml'),MunitTools::isEmptyString()])]
  ```

- [allOf(Matchers\[\])](core-matchers-reference#allof-matchers) checks if all of the matchers are
  successful.

  Example:

  ```DataWeave
  #[MunitTools::allOf([MunitTools::notNullValue(),MunitTools::withMediaType('text/xml'),MunitTools::isEmptyString()])]
  ```

## Match Strings

String Matchers perform assertions on String expressions:

- Does the expression contain a specified string?

- Does the expression start or end with a specified string?

- Does the string in the expression have zero length?

- Does the string in the expression match a specified string?

String Matchers:

- [containsString(String)](https://docs.mulesoft.com/munit/latest/string-matchers-reference#containsstring-string) checks that the
  expression contains the specified String.

  Example:

  ```DataWeave
  #[MunitTools::containsString('example')]
  ```

- [startsWith(String)](https://docs.mulesoft.com/munit/latest/string-matchers-reference#startswith-string) checks that the expression
  starts with the specified String.

  Example:

  ```DataWeave
  #[MunitTools::startsWith('exam')]
  ```

- [endsWith(String)](https://docs.mulesoft.com/munit/latest/string-matchers-reference#endswith-string) checks that the expression ends with
  the specified String.

  Example:

  ```DataWeave
  #[MunitTools::endsWith('ple')]
  ```

- [isEmptyString()](https://docs.mulesoft.com/munit/latest/string-matchers-reference#isemptystring) checks that the expression has zero
  length.

  Example:

  ```DataWeave
  #[MunitTools::isEmptyString()]
  ```

- [isEmptyOrNullString()](https://docs.mulesoft.com/munit/latest/string-matchers-reference#isemptyornullstring) checks that the expression
  is null, or has zero length.

  Example:

  ```DataWeave
  #[MunitTools::isEmptyOrNullString()]
  ```

- [equalToIgnoringCase(String)](https://docs.mulesoft.com/munit/latest/string-matchers-reference#equaltoignoringcase-string) checks that
  the expression is equal to the specified String, ignoring case.

  Example:

  ```DataWeave
  #[MunitTools::equalToIgnoringCase('example')]
  ```

- [equalToIgnoringWhiteSpace(String)](https://docs.mulesoft.com/munit/latest/string-matchers-reference#equaltoignoringwhitespace-string)
  checks that the expression is equal to the string disregarding leading and trailing white spaces,
  and compressing all inner white spaces to a single space.

  Example:

  ```DataWeave
  #[MunitTools::equalToIgnoringWhiteSpace('An Example')]
  ```

- [stringContainsInOrder(String, String,…​)](https://docs.mulesoft.com/munit/latest/string-matchers-reference#stringcontainsinorder-array-string)
  checks that the expression contains all of the specified substrings, regardless of the order of
  their appearance.

  Example:

  ```DataWeave
  is="#[MunitTools::stringContainsInOrder(['an', 'example'])]"/>
  ```

## Match Comparable Expressions

Comparable matchers compare the expression against a specified value:

- Is the expression’s value bigger or smaller than a specified value?

- Is the expression’s value closer to a specific number?

Some comparable matchers take a `Comparable` type. `Comparable` is a DataWeave type that represents
all the types that can be compared to each other. Allowed primitives are `String`, `Number`,
`Boolean`, `DateTime`, `LocalDateTime`, `LocalTime`, `Time`, and `TimeZone`.

Comparable Matchers:

- [greaterThan(Comparable)](https://docs.mulesoft.com/munit/latest/comparable-matchers-reference#greaterthan-comparable) checks that the
  expression is greater than the specified value.

  Examples:

  ```DataWeave
  #[MunitTools::greaterThan(20)]
  ```

  ```DataWeave
  #[MunitTools::greaterThan(|2017-08-09|)]
  ```

- [greaterThanOrEqualTo(Comparable)](https://docs.mulesoft.com/munit/latest/comparable-matchers-reference#greaterthanorequalto-comparable)
  checks that the expression is greater than or equal to the specified value.

  Examples:

  ```DataWeave
  #[MunitTools::greaterThanOrEqualTo(20)]
  ```

  ```DataWeave
  #[MunitTools::greaterThanOrEqualTo(|2017-08-09|)]
  ```

- [lessThan(Comparable)](https://docs.mulesoft.com/munit/latest/comparable-matchers-reference#lessthan-comparable) checks that the
  expression is less than the specified value.

  Examples:

  ```DataWeave
  #[MunitTools::lessThan(20)
  ```

  ```DataWeave
  #[MunitTools::lessThan(|2017-08-09|)]
  ```

- [lessThanOrEqualTo(Comparable)](https://docs.mulesoft.com/munit/latest/comparable-matchers-reference#lessthanorequalto-comparable) checks
  that the expression is less than or equal to the specified value.

  Examples:

  ```DataWeave
  #[MunitTools::lessThanOrEqualTo(20)]
  ```

  ```DataWeave
  #[MunitTools::lessThanOrEqualTo(|2017-08-09|)]
  ```

- [closeTo(Number, Number)](https://docs.mulesoft.com/munit/latest/comparable-matchers-reference#closeto-number-number) checks that the
  expression is in the range defined by the first and second number.

  Example:

  ```DataWeave
  #[MunitTools::closeTo(1, 0.01)]
  ```

- [equalTo(Object)](https://docs.mulesoft.com/munit/latest/comparable-matchers-reference#equalto-object) checks that the expression is
  equal to a specified value. This matcher also accepts DataWeave objects.

  Examples:

  ```DataWeave
  #[MunitTools::equalTo('example')]
  ```

  ```DataWeave
  #[MunitTools::equalTo({example1: 1 , example2: 2}]
  ```

## Match Maps and Iterations

Use iterable matchers and maps matchers when your expression is an array or a map of data:

- Is the map or array in the expression empty?

- Does the map or array in the expression have a specific key?

- Is every item in the array from the expression greater than or less than a specific number?

- Does any item in the array from the expression start or end with a specified string?

Iterable and Map Matchers:

- [everyItem(Matcher)](https://docs.mulesoft.com/munit/latest/iterable-map-matchers-reference#everyitem-matcher) checks that every element
  in the expression matches the specified matcher. This matcher works only for arrays.

  Examples:

  ```DataWeave
  #[MunitTools::everyItem(MunitTools::notNullValue())]
  ```

  ```DataWeave
  #[MunitTools::everyItem(MunitTools::startsWith('a'))]
  ```

- [hasItem(Matcher)](https://docs.mulesoft.com/munit/latest/iterable-map-matchers-reference#hasitem-matcher) checks that any element in the
  expression matches the specified matcher. This matcher works only for arrays.

  Examples:

  ```DataWeave
  #[MunitTools::hasItem(MunitTools::notNullValue())]
  ```

  ```DataWeave
  #[MunitTools::hasItem(MunitTools::startsWith('a'))]
  ```

- [hasSize(Matcher)](https://docs.mulesoft.com/munit/latest/iterable-map-matchers-reference#hassize-matcher) checks that the size of the
  expression matches the specified matcher.

  Examples:

  ```DataWeave
  #[MunitTools::hasSize(MunitTools::equalTo(5))]
  ```

  ```DataWeave
  #[MunitTools::hasSize(MunitTools::greaterThan(5))]
  ```

- [isEmpty()](https://docs.mulesoft.com/munit/latest/iterable-map-matchers-reference#isempty) checks that the expression is an empty
  collection.

  Examples:

  ```DataWeave
  #[MunitTools::isEmpty()]
  ```

- [hasKey(Matcher)](https://docs.mulesoft.com/munit/latest/iterable-map-matchers-reference#haskey-matcher) checks that the expression has a
  key that matches the specified matcher. This matcher works only for maps.

  Examples:

  ```DataWeave
  #[MunitTools::hasKey(MunitTools::equalTo('myKey'))]
  ```

  ```DataWeave
  #[MunitTools::hasKey(MunitTools::startsWith('a'))]
  ```

- [hasValue(Matcher)](https://docs.mulesoft.com/munit/latest/iterable-map-matchers-reference#hasvalue-matcher) checks that the expression
  has a value that matches the specified matcher. This matcher works only for maps.

  Examples:

  ```DataWeave
  #[MunitTools::hasValue(MunitTools::equalTo('myValue'))]
  ```

  ```DataWeave
  #[MunitTools::hasValue(MunitTools::startsWith('a'))]
  ```

## See Also

- [Core Matchers Reference](https://docs.mulesoft.com/munit/latest/core-matchers-reference)

- [String Matchers Reference](https://docs.mulesoft.com/munit/latest/string-matchers-reference)

- [Iterable and Map Matchers Reference](https://docs.mulesoft.com/munit/latest/iterable-map-matchers-reference)

- [Assert That Event Processor](https://docs.mulesoft.com/munit/latest/assertion-event-processor)
