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