All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.has_assertion_template_for_real_number.txt Maven / Gradle / Ivy


  /**
   * 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>";

    // check
    ${propertyType} actual${Property} = actual.get${Property}();
    if (actual${Property} != ${property_safe}) {
      failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
    }

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

  /**
   * Verifies that the actual ${class_to_assert}'s ${property} is close to the given value by less than the given offset.
   * 

* If difference is equal to the offset value, assertion is considered successful. * @param ${property_safe} the value to compare the actual ${class_to_assert}'s ${property} to. * @param offset the given offset. * @return this assertion object. * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not close enough to the given value.${throws_javadoc} */ public ${self_type} has${Property}CloseTo(${propertyType} ${property_safe}, ${propertyType} offset) ${throws}{ // check that actual ${class_to_assert} we want to make assertions on is not null. isNotNull(); ${propertyType} actual${Property} = actual.get${Property}(); // overrides the default error message with a more explicit one String assertjErrorMessage = String.format("\nExpecting ${property}:\n <%s>\nto be close to:\n <%s>\nby less than <%s> but difference was <%s>", actual${Property}, ${property_safe}, offset, Math.abs(${property_safe} - actual${Property})); // check Assertions.assertThat(actual${Property}).overridingErrorMessage(assertjErrorMessage).isCloseTo(${property_safe}, Assertions.within(offset)); // return the current assertion for method chaining return ${myself}; }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy