How do you assert that a string contains a specific substring in AssertJ?
A) contains()
B) hasSubstring()
C) includes()
D) isPartOf()
Answer:
A) contains()
Explanation:
The contains()
method in AssertJ is used to assert that a string contains a specific substring. It verifies that the specified substring is present within the string.
For example:
import static org.assertj.core.api.Assertions.assertThat;
String message = "Hello, World!";
assertThat(message).contains("World");
In this example, the contains()
method asserts that the string message
contains the substring “World”.