Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginner in Java using JUnit to test an ArrayList size

Tags:

java

junit

    @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?

like image 853
Yosua Martiansia Avatar asked Feb 13 '26 17:02

Yosua Martiansia


2 Answers

Either you use

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

or

assertEquals(4, points.size());
like image 138
more Avatar answered Feb 16 '26 05:02

more


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);
like image 43
tam.teixeira Avatar answered Feb 16 '26 07:02

tam.teixeira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!