I'm trying to test the 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 get the following error:
The method assertEquals(Object, Object) is ambiguous for the type TestClass
What am I doing wrong? The return type of calculate is an 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));
}
Your call to assertEquals has one argument of type long and the other of type 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 cast to a long of an int literal.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With