Contact Us 1-800-596-4880

Comparable Matchers Reference

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 that you can pass any primitive value such as an integer or a date.

greaterThan(Comparable)

Checks that the expression is greater than the specified value.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::greaterThan(|2017-08-09|)]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::greaterThan(20)]"/>

greaterThanOrEqualTo(Comparable)

Checks that the expression is greater than or equal to the specified value.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::greaterThanOrEqualTo(20)]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::greaterThanOrEqualTo(|2017-08-09|)]"/>

lessThan(Comparable)

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::lessThan(20)]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::lessThan(|2017-08-09|)]"/>

lessThanOrEqualTo(Comparable)

Checks that the expression is less than or equal to the specified value.

Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::lessThanOrEqualTo(20)]"/>
Example
<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::lessThanOrEqualTo(|2017-08-09|)]"/>

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.

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

<!--
  This evaluates if the expression is between 0.99 (1 - 0.01) and 1.01 (1 + 0.01)
-->

equalTo(Object)

Checks that the expression is equal to a specific value.

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

This matcher also accepts Dataweave objects.

Example
<munit-tools:assert-that
expression="#[{example1: 1 , example2: 2}]"
is="#[MunitTools::equalTo({example1: 1 , example2: 2})]"/>

The matcher validates that the keys and their respective values are the same.
The order in the matcher must be the same as the one in the expression or the assertion fails.

Example
<munit-tools:assert-that
expression="#[{example1: 1 , example2: 2}]"
is="#[MunitTools::equalTo({example2: 2 , example1: 1})]"/>

<!-- This assertion fails -->
Example
<munit-tools:assert-that
expression="#[[1, 2, 3]]"
is="#[MunitTools::equalTo([3, 2, 1])]"/>

<!-- This assertion fails -->