Yosua Martiansia
Yosua Martiansia

Reputation: 135

Beginner in Java using JUnit to test an ArrayList size

    @Test
    @DisplayName("Get all Points in Shape is working and gets the correct number output")
    public void test_Get_All_Points_On_Shape()
    {
        ArrayList<Point> points = new ArrayList<Point>(Arrays.asList(new Point[4]));
        assertEquals(points.size() == 4);
    }

the above code gives an error

The method assertEquals(short, short) in the type Assertions is not applicable for the arguments (boolean)

How to resolve this problem?

Upvotes: 3

Views: 17915

Answers (5)

tam.teixeira
tam.teixeira

Reputation: 863

If you use assertThat() from org.assertj.core.api.AssertionsForClassTypes.assertThat or from org.assertj.core.api.Assertions.assertThat

then you can use:

assertThat(points).hasSize(4);

Upvotes: 2

sachyy
sachyy

Reputation: 612

You can use the Assert options appropriately as per your need. two easy methods that can be used for your case is

assertEquals(4, points.size());
assertTrue(points.size() == 4);

depending on your requirement, you can use the assertFalse() which is also a much used method.

Upvotes: 0

Rafał Maciak
Rafał Maciak

Reputation: 206

The method assertEquals() takes two parameters:

  • expected value and
  • actual value

What you passed is a result of equality operator on two integers, which is boolean.

You have to change this line to the following:

 assertEquals(4, points.size());

Upvotes: 1

Yomal
Yomal

Reputation: 361

Please check http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertEquals(long,%20long)

The assertEquals method requires two parameters. Replace your code as assertEquals(4,points.size());

Upvotes: 1

more
more

Reputation: 125

Either you use

assertTrue(points.size() == 4);

or

assertEquals(4, points.size());

Upvotes: 8

Related Questions