What method is used in AssertJ to check if a collection is empty?

What method is used in AssertJ to check if a collection is empty?

A) isEmpty()
B) isNull()
C) hasSize(0)
D) containsNothing()

Answer:

A) isEmpty()

Explanation:

The isEmpty() method in AssertJ is used to assert that a collection is empty. It checks whether the collection contains no elements.

For example:


import static org.assertj.core.api.Assertions.assertThat;

List<String> emptyList = new ArrayList<>();

assertThat(emptyList).isEmpty();

In this example, the isEmpty() method asserts that the list emptyList is empty.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top