Bug 235107 - Eclipse's JUnit produce invalid assertEquals outcome
Summary: Eclipse's JUnit produce invalid assertEquals outcome
Status: VERIFIED NOT_ECLIPSE
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.2   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.4 RC4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-02 07:51 EDT by Nattapong Sirilappanich CLA
Modified: 2008-06-06 09:04 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nattapong Sirilappanich CLA 2008-06-02 07:51:10 EDT
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.
Comment 1 Philipe Mulet CLA 2008-06-02 12:28:29 EDT
> 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
	}
}
Comment 2 Nattapong Sirilappanich CLA 2008-06-02 23:19:05 EDT
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).
Comment 3 Philipe Mulet CLA 2008-06-03 09:44:57 EDT
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
Comment 4 Frederic Fusier CLA 2008-06-06 09:04:23 EDT
Verified