How do you assert that a collection has a specific size in AssertJ?
A) hasSize()
B) sizeEquals()
C) isOfSize()
D) containsSize()
Answer:
A) hasSize()
Explanation:
The hasSize()
method in AssertJ is used to assert that a collection has a specific size. It verifies that the collection contains the expected number of elements.
For example:
import static org.assertj.core.api.Assertions.assertThat;
List<String> list = Arrays.asList("apple", "banana", "cherry");
assertThat(list).hasSize(3);
In this example, the hasSize()
method asserts that the list list
contains 3 elements.