Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assertEquals problems (object object) (long long)

Tags:

java

junit

Interval<Integer> interval1 = Intervals.open(3, 6);

Here 3 is the lower bound, and 6 is the upper bound.

assertEquals(interval1.lowerBound(), 3);

After writing the test, there is a red underline saying:

ambiguous method call.Both assertEquals(object, object) assertEquals(long, long)
like image 269
SHR Avatar asked Apr 09 '15 03:04

SHR


1 Answers

The problem is that you're calling assertEquals with a Long and an int, so the compiler can't tell whether you want assertEquals(long, long) (autounboxing the Long) or assertEquals(Object, Object) (autoboxing the int).

To fix this, you need to handle the unboxing or boxing yourself, by writing either this:

assertEquals(3L, interval1.lowerBound().longValue());

or this:

assertEquals(Long.valueOf(3L), interval1.lowerBound());

(Incidentally, note that I swapped the order of the two arguments for you. assertEquals expects the first argument to be the expected value and the second to be the actual value. This doesn't affect the assertion itself, but it affects the exception-message that's generated when the assertion fails.)

like image 65
ruakh Avatar answered Oct 21 '22 23:10

ruakh