Re: Re: Asserts using Comparable.compareTo() instead of equals() (for BigDecimal and others)

Malte Finsterwalder <[email protected]> Sun, 16 Mar 2014 12:45:33 +0100
Newsgroups gmane.comp.java.junit.user
Message-ID <CALS12-ONGJhhX3=zsdBdXoZ0ac5VbTwQQRf5icy8HVt5dR-ffQ@mail.gmail.com>
Hi Miguel,

I think you should find all you need in Hamcrest class
org.hamcrest.Matchers already.
At least in Hamcrest 1.3, which I'm using. See:
http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html

There you find the following methods:
*comparesEqualTo
<http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html#comparesEqualTo(T)>*
(T value)
          Creates a matcher of Comparable object that matches when the
examined object is equal to the specified value, as reported by the
compareTo method of the *examined* object.
*greaterThan
<http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html#greaterThan(T)>*
(T value)
          Creates a matcher of Comparable object that matches when the
examined object is greater than the specified value, as reported by the
compareTo method of the *examined* object.
*greaterThanOrEqualTo
<http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html#greaterThanOrEqualTo(T)>*
(T value)
          Creates a matcher of Comparable object that matches when the
examined object is greater than or equal to the specified value, as
reported by the compareTo method of the *examined* object.
*lessThan
<http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html#lessThan(T)>*
(T value)
          Creates a matcher of Comparable object that matches when the
examined object is less than the specified value, as reported by the
compareTo method of the *examined* object.
*lessThanOrEqualTo
<http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html#lessThanOrEqualTo(T)>*
(T value)
          Creates a matcher of Comparable object that matches when the
examined object is less than or equal to the specified value, as reported
by the compareTo method of the *examined* object.

Greetings,
   Malte