Search code examples
javaassert

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.


Solution

  • 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());