0

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?

Max
  • 9,100
  • 25
  • 72
  • 109
  • please include your import section. – mhrsalehi Jul 13 '22 at 15:28
  • 1
    Have you read [this post](https://stackoverflow.com/questions/1811103/java-junit-the-method-x-is-ambiguous-for-type-y)? their your error is broken down and explained. – Benniesmalls Jul 13 '22 at 15:30
  • Does this answer your question? [Java JUnit: The method X is ambiguous for type Y](https://stackoverflow.com/questions/1811103/java-junit-the-method-x-is-ambiguous-for-type-y) – Thomas Kläger Jul 13 '22 at 16:27

2 Answers2

1

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:

fabio19933
  • 124
  • 8
0
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)
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Rajesh G
  • 1
  • 1
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 02 '22 at 18:10