I want to use assert between 2 two decimal, I use this:
BigDecimal bd1 = new BigDecimal (1000);
BigDecimal bd2 = new BigDecimal (1000);
org.junit.Assert.assertSa
The method assertSame
tests that both are the same object. However, you have two objects which have the same value. To test this, you can use assertEquals
.
However, you should be aware of some unexpected behavior when using assertEquals
(which depends on the equals
method) on BigDecimal
s. For example, new BigDecimal("100").divide(new BigDecimal("10.0")).equals(new BigDecimal("10"))
evaluates to false
because equals
also looks at the scale of the BigDecimal
instances.
In many circumstances it is better to compare BigDecimal
s by using the compareTo
method:
assertTrue(bd1.compareTo(bd2) == 0);