Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property-not-null assertion template #158

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/resources/templates/has_any_assertion_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

/**
* Verifies that ${class_to_assert}'s ${property} is not null.
* @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
* @return this assertion object.
* @throws AssertionError - if the actual ${class_to_assert}'s ${property} is null.${throws_javadoc}
*/
public ${self_type} has${Property}() {
// check that actual ${class_to_assert} we want to make assertions on is not null.
isNotNull();

// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto not be null";

// null safe check
${propertyType} actual${Property} = actual.${getter}();
if (actual${Property} == null) {
failWithMessage(assertjErrorMessage, actual);
}

// return the current assertion for method chaining
return ${myself};
}