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

Marc Philipp <[email protected]> Sun, 16 Mar 2014 13:03:58 +0100
Newsgroups gmane.comp.java.junit.user
Message-ID <[email protected]>
For BigDecimals there's also

closeTo(java.math.BigDecimal operand, java.math.BigDecimal error) 
          Creates a matcher of BigDecimals that matches when an examined BigDecimal is equal to the specified operand, within a range of +/- error.

Cheers, Marc


Am 16.03.2014 um 12:45 schrieb Malte Finsterwalder <[email protected]>:

> 
> 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(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(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(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(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(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
> 
>