Which method in AssertJ is used to start an assertion chain?

Which method in AssertJ is used to start an assertion chain?

A) assertThat()
B) assertTrue()
C) assertEquals()
D) assertNotNull()

Answer:

A) assertThat()

Explanation:

The assertThat() method in AssertJ is used to start an assertion chain. It allows you to specify the object or value that you want to make assertions about, and then chain multiple assertions in a fluent and readable manner.

For example:


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

assertThat("Hello World")
    .isNotNull()
    .startsWith("Hello")
    .endsWith("World");

In this example, assertThat() is used to start an assertion chain on the string “Hello World”, allowing multiple assertions to be chained together.

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