Community
Participate
Working Groups
Build ID: M20080221-1800 Steps To Reproduce: 1.New JUnit 4.0 test case 2.put this method in test case @org.junit.Test public void testXXX() { assertEquals(123456789.345, 123456789.34); } 3.outcome is pass. More information: Giving wrapper class(Double) yield the same result. Using wrapper class(Double) to compare between above number yeild false.
> Giving wrapper class(Double) yield the same result. > Using wrapper class(Double) to compare between above number yeild false. What do you mean by this ? Given JUnit4 performs a Number/longValue() comparison, these results are not surprising. FYI, here is a simple standalone program which prints the following: D1.equals(D2) :false d1==d2 :false N1.longValue()==N2.longValue() :true public class X { static void assertEquals1(Double d1, Double d2) { System.out.println("D1.equals(D2) :" +d1.equals(d2)); } static void assertEquals2(double d1, double d2) { System.out.println("d1==d2 :" + (d1 == d2)); } static void assertEquals3(Object o1, Object o2) { System.out.println("N1.longValue()==N2.longValue() :" + (((Number)o1).longValue() == ((Number)o2).longValue())); } public static void main(String[] args) { assertEquals1(123456789.345, 123456789.34); // false assertEquals2(123456789.345, 123456789.34); // false assertEquals3(123456789.345, 123456789.34); // true } }
Hi, Did you mean JUnit will call method longValue() to make a comparison? Why doesn't it just simply call equals(Object)? I'm expecting polymorphic mechanism applied when perform assertEquals(Object, Object).
I thought you were alluding to an Eclipse bug. If you disagree with JUnit behavior, please report the issue to them (http://junit.org/). Closing as NOT ECLIPSE
Verified