SHR
SHR

Reputation: 81

assertEquals problems (object object) (long long)

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)

Upvotes: 8

Views: 8160

Answers (1)

ruakh
ruakh

Reputation: 183301

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.)

Upvotes: 13

Related Questions