001package tech.uom.lib.assertj.assertions; 002 003import javax.measure.Quantity; 004import org.assertj.core.api.AbstractObjectAssert; 005import org.assertj.core.util.Objects; 006 007/** 008 * Abstract base class for {@link Quantity} specific assertions - Generated by CustomAssertionGenerator. 009 */ 010@javax.annotation.Generated(value="assertj-assertions-generator") 011public abstract class AbstractQuantityAssert<S extends AbstractQuantityAssert<S, A>, A extends Quantity> extends AbstractObjectAssert<S, A> { 012 013 /** 014 * Creates a new <code>{@link AbstractQuantityAssert}</code> to make assertions on actual Quantity. 015 * @param actual the Quantity we want to make assertions on. 016 */ 017 protected AbstractQuantityAssert(A actual, Class<S> selfType) { 018 super(actual, selfType); 019 } 020 021 /** 022 * Verifies that the actual Quantity's unit is equal to the given one. 023 * @param unit the given unit to compare the actual Quantity's unit to. 024 * @return this assertion object. 025 * @throws AssertionError - if the actual Quantity's unit is not equal to the given one. 026 */ 027 public S hasUnit(javax.measure.Unit unit) { 028 // check that actual Quantity we want to make assertions on is not null. 029 isNotNull(); 030 031 // overrides the default error message with a more explicit one 032 String assertjErrorMessage = "\nExpecting unit of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; 033 034 // null safe check 035 javax.measure.Unit actualUnit = actual.getUnit(); 036 if (!Objects.areEqual(actualUnit, unit)) { 037 failWithMessage(assertjErrorMessage, actual, unit, actualUnit); 038 } 039 040 // return the current assertion for method chaining 041 return myself; 042 } 043 044 /** 045 * Verifies that the actual Quantity's value is equal to the given one. 046 * @param value the given value to compare the actual Quantity's value to. 047 * @return this assertion object. 048 * @throws AssertionError - if the actual Quantity's value is not equal to the given one. 049 */ 050 public S hasValue(Number value) { 051 // check that actual Quantity we want to make assertions on is not null. 052 isNotNull(); 053 054 // overrides the default error message with a more explicit one 055 String assertjErrorMessage = "\nExpecting value of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; 056 057 // null safe check 058 Number actualValue = actual.getValue(); 059 if (!Objects.areEqual(actualValue, value)) { 060 failWithMessage(assertjErrorMessage, actual, value, actualValue); 061 } 062 063 // return the current assertion for method chaining 064 return myself; 065 } 066 067}