assertj-templates.has_assertion_template.txt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of codingstyle Show documentation
Show all versions of codingstyle Show documentation
Provides all necessary resources for a Java project to enforce the coding style that I am using
in my lectures about software development at Munich University of Applied Sciences and in all of my
open source projects. It configures several static analysis tools for Maven and IntelliJ. Moreover,
it provides some sample classes that already use this style guide. This classes can be used as such but are not
required in this project. These classes also use some additional libraries that are included using the Maven
dependency mechanism. If the sample classes are deleted then the dependencies can be safely deleted, too.
/**
* Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
* @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 not equal to the given one.${throws_javadoc}
*/
public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
// 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 be:\n <%s>\nbut was:\n <%s>";
// null safe check
${propertyType} actual${Property} = actual.${getter}();
if (!java.util.Objects.deepEquals(actual${Property}, ${property_safe})) {
failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
}
// return the current assertion for method chaining
return ${myself};
}