Sahil
Sahil

Reputation: 9480

Method assertEquals(Object, Object) is ambiguous for the type?

My code snippet looks like this

@Test
public void testAddAndGet1() {
    ArrayList<Integer> list = new ArrayList<Integer>();

    list.add(42);
    list.add(-3);
    list.add(17);
    list.add(99);
    assertEquals(42, list.get(0));
    assertEquals(-3, list.get(1));
    assertEquals(17, list.get(2));
    assertEquals(99, list.get(3));

    assertEquals("second attempt", 42, list.get(0));   // make sure I can get them a second time
    assertEquals("second attempt", 99, list.get(3));
}

I am receiving Method assertEquals(Object, Object) is ambiguous for the type. I am not sure why I am getting it?

Upvotes: 0

Views: 2149

Answers (2)

Rajesh G
Rajesh G

Reputation: 1

import static org.junit.Assert.*;
import org.junit.Test;

//import static org.junit.jupiter.api.Assertions.*;

//import org.junit.jupiter.api.Test; (make this out by commenting then this works fine i just tested now)

Upvotes: 0

fabio19933
fabio19933

Reputation: 124

Maybe you have got this error because you trying to compare two different type (int,Integer) try to cast one of the parameter

Maybe this post can helps you: Ambiguous method call Both assertEquals(Object, Object) in Assert and assertEquals(double, double) in Assert match:

Upvotes: 1

Related Questions