SELF
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.Assert<SELF,ACTUAL>
, ComparableAssert<SELF,BigDecimal>
, Descriptable<SELF>
, ExtensionPoints<SELF,ACTUAL>
, NumberAssert<SELF,BigDecimal>
BigDecimalAssert
public abstract class AbstractBigDecimalAssert<SELF extends AbstractBigDecimalAssert<SELF>> extends AbstractComparableAssert<SELF,BigDecimal> implements NumberAssert<SELF,BigDecimal>
BigDecimal
s.actual, info, myself
Constructor | Description |
---|---|
AbstractBigDecimalAssert(BigDecimal actual,
Class<?> selfType) |
Modifier and Type | Method | Description |
---|---|---|
SELF |
isBetween(BigDecimal start,
BigDecimal end) |
Verifies that the actual value is in [start, end] range (start and end included).
|
SELF |
isCloseTo(BigDecimal expected,
Offset<BigDecimal> offset) |
Verifies that the actual number is close to the given one within the given offset.
If difference is equal to offset value, assertion is considered valid. |
SELF |
isCloseTo(BigDecimal expected,
Percentage percentage) |
Verifies that the actual number is close to the given one within the given percentage.
If difference is equal to the percentage value, assertion is considered valid. |
SELF |
isEqualByComparingTo(String expected) |
Same as
isEqualByComparingTo(BigDecimal) but
takes care of converting given String to BigDecimal . |
SELF |
isEqualTo(String expected) |
Same as
isEqualTo(BigDecimal) but takes care of converting given String to
BigDecimal for you. |
SELF |
isNegative() |
Verifies that the actual value is negative.
|
SELF |
isNotCloseTo(BigDecimal expected,
Offset<BigDecimal> offset) |
Verifies that the actual number is not close to the given one by less than the given offset.
If the difference is equal to the offset value, the assertion fails. |
SELF |
isNotCloseTo(BigDecimal expected,
Percentage percentage) |
Verifies that the actual number is not close to the given one by the given percentage.
If difference is equal to the percentage value, the assertion fails. |
SELF |
isNotEqualByComparingTo(String expected) |
Same as
isNotEqualByComparingTo(BigDecimal) but
takes care of converting given String to BigDecimal . |
SELF |
isNotNegative() |
Verifies that the actual value is non negative (positive or equal zero).
|
SELF |
isNotPositive() |
Verifies that the actual value is non positive (negative or equal zero).
|
SELF |
isNotZero() |
Verifies that the actual value is not equal to zero.
|
SELF |
isOne() |
Verifies that the actual value is equal to one.
|
SELF |
isPositive() |
Verifies that the actual value is positive.
|
SELF |
isStrictlyBetween(BigDecimal start,
BigDecimal end) |
Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).
|
SELF |
isZero() |
Verifies that the actual value is equal to zero.
|
SELF |
usingComparator(Comparator<? super BigDecimal> customComparator) |
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingDefaultComparator() |
Revert to standard comparison for incoming assertion checks.
|
asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasToString, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, withFailMessage, withRepresentation, withThreadDumpOnError
inBinary, inHexadecimal, isEqualByComparingTo, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo, isNotEqualByComparingTo
as, as, defaultTypeComparators, extracting, extracting, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, returns, usingComparatorForFields, usingComparatorForType
public AbstractBigDecimalAssert(BigDecimal actual, Class<?> selfType)
public SELF isZero()
Example:
// assertions will pass
assertThat(0).isZero();
assertThat(0.0).isZero();
// assertions will fail
assertThat(42).isZero();
assertThat(3.142).isZero();
Example:
// assertion will pass
assertThat(BigDecimal.ZERO).isZero();
// assertion will fail
assertThat(new BigDecimal("8.00")).isZero();
isZero
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
public SELF isNotZero()
Example:
// assertions will pass
assertThat(42).isNotZero();
assertThat(3.142).isNotZero();
// assertions will fail
assertThat(0).isNotZero();
assertThat(0.0).isNotZero();
Example:
// assertion will pass
assertThat(new BigDecimal("8.00")).isNotZero();
// assertion will fail
assertThat(BigDecimal.ZERO).isNotZero();
isNotZero
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
public SELF isOne()
Example:
// assertions will pass
assertThat(1).isOne();
assertThat(1.0).isOne();
// assertions will fail
assertThat(42).isOne();
assertThat(3.142).isOne();
Example:
// assertion will pass
assertThat(BigDecimal.ONE).isOne();
// assertion will fail
assertThat(new BigDecimal("8.00")).isOne();
isOne
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
public SELF isPositive()
Example:
// assertions will pass
assertThat(42).isPositive();
assertThat(3.142).isPositive();
// assertions will fail
assertThat(0).isPositive();
assertThat(-42).isPositive();
Example:
// assertion will pass
assertThat(new BigDecimal("8.0")).isPositive();
// assertion will fail
assertThat(new BigDecimal("-8.0")).isPositive();
isPositive
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
public SELF isNegative()
Example:
// assertions will pass
assertThat(-42).isNegative();
assertThat(-3.124).isNegative();
// assertions will fail
assertThat(0).isNegative();
assertThat(42).isNegative();
Example:
// assertion will pass
assertThat(new BigDecimal("-8.0")).isNegative();
// assertion will fail
assertThat(new BigDecimal("8.0")).isNegative();
isNegative
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
public SELF isNotPositive()
Example:
// assertions will pass
assertThat(-42).isNotPositive();
assertThat(0).isNotPositive();
// assertions will fail
assertThat(42).isNotPositive();
assertThat(3.124).isNotPositive();
Example:
// assertion will pass
assertThat(new BigDecimal("-8.0")).isNotPositive();
// assertion will fail
assertThat(new BigDecimal("8.0")).isNotPositive();
isNotPositive
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
this
assertion object.public SELF isNotNegative()
Example:
// assertions will pass
assertThat(42).isNotNegative();
assertThat(0).isNotNegative();
// assertions will fail
assertThat(-42).isNotNegative();
assertThat(-3.124).isNotNegative();
Example:
// assertion will pass
assertThat(new BigDecimal("8.0")).isNotNegative();
// assertion will fail
assertThat(new BigDecimal("-8.0")).isNotNegative();
isNotNegative
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
this
assertion object.public SELF isBetween(BigDecimal start, BigDecimal end)
Example:
// assertions will pass
assertThat(new BigDecimal("8.0")).isBetween(new BigDecimal("7.0"), new BigDecimal("9.0"));
assertThat(new BigDecimal("8.00")).isBetween(new BigDecimal("7.0"), new BigDecimal("9.0"));
assertThat(new BigDecimal("8.0")).isBetween(new BigDecimal("8.0"), new BigDecimal("9.0"));
assertThat(new BigDecimal("8.0")).isBetween(new BigDecimal("7.0"), new BigDecimal("8.0"));
// assertion will fail
assertThat(new BigDecimal("8.0")).isBetween(new BigDecimal("6.0"), new BigDecimal("7.0"));
Note that comparison of BigDecimal
is done by value without scale consideration, i.e 2.0 and 2.00 are
considered equal in value (not like BigDecimal.equals(Object)
.
isBetween
in interface ComparableAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
isBetween
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
isBetween
in class AbstractComparableAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
start
- the start value (inclusive), expected not to be null.end
- the end value (inclusive), expected not to be null.public SELF isStrictlyBetween(BigDecimal start, BigDecimal end)
Example:
// assertion will pass
assertThat(new BigDecimal("8.0")).isStrictlyBetween(new BigDecimal("7.0"), new BigDecimal("9.0"));
// assertions will fail
assertThat(new BigDecimal("8.0")).isStrictlyBetween(new BigDecimal("8.0"), new BigDecimal("9.0"));
assertThat(new BigDecimal("8.0")).isStrictlyBetween(new BigDecimal("7.0"), new BigDecimal("8.0"));
isStrictlyBetween
in interface ComparableAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
isStrictlyBetween
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
isStrictlyBetween
in class AbstractComparableAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
start
- the start value (exclusive), expected not to be null.end
- the end value (exclusive), expected not to be null.public SELF isEqualTo(String expected)
isEqualTo(BigDecimal)
but takes care of converting given String to
BigDecimal
for you.
Example:
// assertion will pass
assertThat(new BigDecimal("8.0")).isEqualTo("8.0");
// assertion will fail because 8.00 is not equals to 8.0
assertThat(new BigDecimal("8.00")).isEqualTo("8.0");
public SELF isEqualByComparingTo(String expected)
isEqualByComparingTo(BigDecimal)
but
takes care of converting given String to BigDecimal
.
Example:
// assertions will pass
assertThat(new BigDecimal("8.0")).isEqualByComparingTo("8.0");
// assertion will pass because 8.0 is equals to 8.00 using BigDecimal.compareTo(Object)
assertThat(new BigDecimal("8.0")).isEqualByComparingTo("8.00");
// assertion will fail
assertThat(new BigDecimal("8.0")).isEqualByComparingTo("2.0");
public SELF isNotEqualByComparingTo(String expected)
isNotEqualByComparingTo(BigDecimal)
but
takes care of converting given String to BigDecimal
.
Example:
// assertions will pass
assertThat(new BigDecimal("8.0")).isNotEqualByComparingTo("7.99");
// assertion will fail
assertThat(new BigDecimal("8.0")).isNotEqualByComparingTo("8.00");
public SELF usingComparator(Comparator<? super BigDecimal> customComparator)
AbstractAssert
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy. Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
usingComparator
in interface Assert<SELF extends AbstractObjectAssert<SELF,ACTUAL>,ACTUAL>
usingComparator
in class AbstractComparableAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public SELF usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.
usingDefaultComparator
in interface Assert<SELF extends AbstractObjectAssert<SELF,ACTUAL>,ACTUAL>
usingDefaultComparator
in class AbstractComparableAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
this
assertion object.public SELF isCloseTo(BigDecimal expected, Offset<BigDecimal> offset)
Example:
final BigDecimal actual = new BigDecimal("8.1");
final BigDecimal other = new BigDecimal("8.0");
// valid assertion
assertThat(actual).isCloseTo(other, within(new BigDecimal("0.2")));
// if difference is exactly equals to given offset value, it's ok
assertThat(actual).isCloseTo(other, within(new BigDecimal("0.1")));
// BigDecimal format has no impact on the assertion, this assertion is valid:
assertThat(actual).isCloseTo(new BigDecimal("8.00"), within(new BigDecimal("0.100")));
// but if difference is greater than given offset value assertion will fail :
assertThat(actual).isCloseTo(other, within(new BigDecimal("0.01")));
isCloseTo
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
expected
- the given number to compare the actual value to.offset
- the given positive offset.this
assertion object.NullPointerException
- if the given offset is null
.NullPointerException
- if the expected number is null
.AssertionError
- if the actual value is not close to the given one.public SELF isNotCloseTo(BigDecimal expected, Offset<BigDecimal> offset)
Example:
final BigDecimal actual = new BigDecimal("8.1");
final BigDecimal other = new BigDecimal("8.0");
// this assertion succeeds
assertThat(actual).isNotCloseTo(other, byLessThan(new BigDecimal("0.01")));
// BigDecimal format has no impact on the assertion, this assertion is valid:
assertThat(actual).isNotCloseTo(new BigDecimal("8.00"), byLessThan(new BigDecimal("0.100")));
// the assertion fails if the difference is equal to the given offset value
assertThat(actual).isNotCloseTo(other, byLessThan(new BigDecimal("0.1")));
// the assertion fails if the difference is greater than the given offset value
assertThat(actual).isNotCloseTo(other, byLessThan(new BigDecimal("0.2")));
isNotCloseTo
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
expected
- the given number to compare the actual value to.offset
- the given positive offset.this
assertion object.NullPointerException
- if the given offset is null
.NullPointerException
- if the expected number is null
.AssertionError
- if the actual value is close to the given one within the offset value.Assertions.byLessThan(BigDecimal)
public SELF isCloseTo(BigDecimal expected, Percentage percentage)
Example with BigDecimal:
// assertions will pass:
assertThat(BigDecimal.valueOf(11.0)).isCloseTo(BigDecimal.TEN, withinPercentage(BigDecimal.valueOf(20d)));
// if difference is exactly equals to the computed offset (1.0), it's ok
assertThat(BigDecimal.valueOf(11.0)).isCloseTo(BigDecimal.TEN, withinPercentage(BigDecimal.valueOf(10d)));
// assertion will fail
assertThat(BigDecimal.valueOf(11.0)).isCloseTo(BigDecimal.TEN, withinPercentage(BigDecimal.valueOf(5d)));
isCloseTo
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
expected
- the given number to compare the actual value to.percentage
- the given positive percentage.this
assertion object.NullPointerException
- if the given offset is null
.NullPointerException
- if the expected number is null
.AssertionError
- if the actual value is not close to the given one.public SELF isNotCloseTo(BigDecimal expected, Percentage percentage)
Example with BigDecimal:
BigDecimal eleven = BigDecimal.valueOf(11.0);
// assertion will pass:
assertThat(eleven).isNotCloseTo(BigDecimal.TEN, withinPercentage(new BigDecimal("5")));
// assertion will fail as the difference is exactly equals to the computed offset (1.0)
assertThat(eleven).isNotCloseTo(BigDecimal.TEN, withinPercentage(new BigDecimal("10")));
// assertion will fail
assertThat(eleven).isNotCloseTo(BigDecimal.TEN, withinPercentage(new BigDecimal("20")));
isNotCloseTo
in interface NumberAssert<SELF extends AbstractBigDecimalAssert<SELF>,BigDecimal>
expected
- the given number to compare the actual value to.percentage
- the given positive percentage.this
assertion object.NullPointerException
- if the given offset is null
.NullPointerException
- if the expected number is null
.AssertionError
- if the actual value is close to the given one.Copyright © 2014–2019. All rights reserved.