Which method in AssertJ is used to check if a string starts with a specific prefix?
A) startsWith()
B) beginsWith()
C) hasPrefix()
D) starts()
Answer:
A) startsWith()
Explanation:
The startsWith()
method in AssertJ is used to assert that a string starts with a specific prefix. It verifies that the string begins with the specified sequence of characters.
For example:
import static org.assertj.core.api.Assertions.assertThat;
String message = "Hello, World!";
assertThat(message).startsWith("Hello");
In this example, the startsWith()
method asserts that the string message
starts with the prefix “Hello”.