Object Validations
You can perform assertions and verifications on objects using the NativeValidationsBuilder.
isEqualTo()
Checks that the actual object is equal to the expected value.
Validations.assertThat().object(actualValue).isEqualTo(expectedValue).perform();
Validations.verifyThat().object(actualValue).isEqualTo(expectedValue).perform();
doesNotEqual()
Checks that the actual object is not equal to the expected value.
Validations.assertThat().object(actualValue).doesNotEqual(expectedValue).perform();
Validations.verifyThat().object(actualValue).doesNotEqual(expectedValue).perform();
contains()
Checks that the actual object contains the expected value.
Validations.assertThat().object(actualText).contains("expected substring").perform();
Validations.verifyThat().object(actualText).contains("expected substring").perform();
doesNotContain()
Checks that the actual object does not contain the expected value.
Validations.assertThat().object(actualText).doesNotContain("unwanted text").perform();
matchesRegex()
Checks that the actual object matches the expected regular expression.
Validations.assertThat().object(actualValue).matchesRegex("\\d{3}-\\d{4}").perform();
doesNotMatchRegex()
Checks that the actual object does not match the expected regular expression.
Validations.assertThat().object(actualValue).doesNotMatchRegex("\\d+").perform();
equalsIgnoringCaseSensitivity()
Checks that the actual object equals the expected value, ignoring case sensitivity.
Validations.assertThat().object("Hello World").equalsIgnoringCaseSensitivity("hello world").perform();
doesNotEqualIgnoringCaseSensitivity()
Checks that the actual object does not equal the expected value, ignoring case sensitivity.
Validations.assertThat().object("Hello").doesNotEqualIgnoringCaseSensitivity("world").perform();
isNull()
Checks that the actual object is null.
Validations.assertThat().object(actualValue).isNull().perform();
isNotNull()
Checks that the actual object is not null.
Validations.assertThat().object(actualValue).isNotNull().perform();
isTrue()
Checks that the actual object evaluates to true.
Validations.assertThat().object(actualValue).isTrue().perform();
isFalse()
Checks that the actual object evaluates to false.
Validations.assertThat().object(actualValue).isFalse().perform();
You can add a custom report message to any object validation:
Validations.assertThat().object(username)
.isEqualTo("admin")
.withCustomReportMessage("Verify username is 'admin'")
.perform();