Geoff
Geoff

Reputation: 753

Ambiguous references to assertEquals

days = DayHelper.getInstance().getDays();
Assert.assertNotNull(days);
Assert.assertEquals(5, days.size());

final Day day = days.get(0);
Assert.assertNotNull(day);
Assert.assertEquals("01/10/2018", day.getId());
Assert.assertEquals("Mon", day.getDay());
Assert.assertEquals(1450, day.getQuota()); //Red underlined
Assert.assertEquals(41, day.getWeekno());  //Red underlined
Assert.assertEquals("Inserted duing DayHelperTest", day.getNote());

In the 'final day' block three of the Asserts compile without issue ... String expected and actual String comes from database

The two that are underlined in red expect Integer and get an Integer.

However, I cannot get rid of the Error below!!!

Error:(56, 19) java: reference to assertEquals is ambiguous both method assertEquals(java.lang.Object,java.lang.Object) in org.junit.Assert and method assertEquals(long,long) in org.junit.Assert match

Can somebody help please.

Thanks.

Upvotes: 2

Views: 6220

Answers (2)

khelwood
khelwood

Reputation: 59186

When I get errors like this with assertEquals, it's because I'm trying to assert that a Long object returned from a method is equal to long primitive value.

Either both arguments should be primitive longs

assertEquals(1450L, (long) day.getQuota());

(which risks a NullPointerException if getQuota() returns null, but your test would be failing anyway)

Or both arguments should be objects

assertEquals(Long.valueOf(1450), day.getQuota());

Upvotes: 2

Óscar López
Óscar López

Reputation: 236124

Try this:

Assert.assertEquals(1450L, day.getQuota());
Assert.assertEquals(41L, day.getWeekno());

Notice the L in front of the numbers? that's the way we specify that the comparison is made between long values.

Upvotes: 0

Related Questions