What method is used in AssertJ to assert that two objects are equal?

What method is used in AssertJ to assert that two objects are equal?

A) isEqualTo()
B) equals()
C) isSameAs()
D) isEquivalentTo()

Answer:

A) isEqualTo()

Explanation:

The isEqualTo() method in AssertJ is used to assert that two objects are equal. It checks whether the actual object is equal to the expected object using the equals() method.

For example:


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

String expected = "Hello";
String actual = "Hello";

assertThat(actual).isEqualTo(expected);

In this example, the isEqualTo() method asserts that the string actual is equal to the string expected.

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