How do you assert that an object is an instance of a specific class in AssertJ?
A) isInstanceOf()
B) isOfType()
C) isClass()
D) hasType()
Answer:
A) isInstanceOf()
Explanation:
The isInstanceOf()
method in AssertJ is used to assert that an object is an instance of a specific class. It checks whether the object is of the specified type.
For example:
import static org.assertj.core.api.Assertions.assertThat;
Object obj = new ArrayList<>();
assertThat(obj).isInstanceOf(List.class);
In this example, the isInstanceOf()
method asserts that the object obj
is an instance of the List
class.