An ambiguous method when testing
I am trying to test a method calculate
from MyClass
:
// TestClass {
@Test
public void testCalculate() {
MyClass tester = new MyClass();
assertEquals((long)123, tester.calculate().get(5));
}
// MyClass
public ArrayList<Long> calculate() {} // signature
Unfortunately I am getting the following error:
The method assertEquals(Object, Object) is ambiguous for the type TestClass
What am I doing wrong? The return type calculate
is ArrayList
with long
-values and I expect the long
number 123.
When I do the following it works:
// TestClass {
@Test
public void testCalculate() {
MyClass tester = new MyClass();
ArrayList<Long> arr = new ArrayList<Long>();
arr.add((long) 123);
assertEquals(arr.get(0), tester.calculate().get(5));
}
source to share
You assertEquals
have one type argument long
and another type in your call long
. Use one of the following:
assertEquals(Long.valueOf(123L), tester.calculate().get(5));
or
assertEquals(123L, tester.calculate().get(5).longValue());
(I suggest using a long
literal 123L
rather than a long
literal listing int
.)
source to share