assert equals int long float

One workaround with some overhead would be to wrap the values in BigDecimal objects, as BigDecimal constructor overloads take long, int and double primitives.

Since new BigDecimal(1l).equals(new BigDecimal(1.0)) holds true,

Assert.assertEquals(new BigDecimal(1.0), new BigDecimal(1l));  

should work for you.

Edit

As Hulk states below, the scale of the BigDecimal objects is used in the equals comparison, but not in the compareTo comparison.
While the scale is set to a default 0 for the constructor taking long, it is inferred through some calculation in the constructor taking double.
Therefore the safest way to compare values (i.e. in edge cases for double values) might be through invoking compareTo and checking the outcome is 0 instead.

Leave a Comment