How do you assert that a string contains a specific substring in AssertJ?

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”.

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