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
bd1
and bd2
are two different objects, and since assertSame checks the object reference using the ==
operator, you're getting that message, see the docs:
Asserts that two objects refer to the same object. If they are not the same, an
AssertionError
without a message is thrown.
You should use assertEquals
instead, it checks that the two objects are equal - which is what you want.
Note that comparing two BigDecimal
objects using the ==
operator will work as long as their values are cached (for 0 through 10) values.