S
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.public abstract class AbstractBigDecimalAssert<S extends AbstractBigDecimalAssert<S>> extends AbstractUnevenComparableAssert<S,BigDecimal> implements NumberAssert<S,BigDecimal>
BigDecimal
s.actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
AbstractBigDecimalAssert(BigDecimal actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
isBetween(BigDecimal start,
BigDecimal end)
Verifies that the actual value is in [start, end] range (start and end included).
|
S |
isCloseTo(BigDecimal other,
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. |
S |
isEqualByComparingTo(String expected)
Same as
isEqualByComparingTo(BigDecimal)
but takes care of converting given String to BigDecimal for you. |
S |
isEqualTo(String expected)
Same as
isEqualTo(BigDecimal) but takes care of converting given String to
BigDecimal for you. |
S |
isNegative()
Verifies that the actual value is negative.
|
S |
isNotNegative()
Verifies that the actual value is non negative (positive or equal zero).
|
S |
isNotPositive()
Verifies that the actual value is non positive (negative or equal zero).
|
S |
isNotZero()
Verifies that the actual value is not equal to zero.
|
S |
isPositive()
Verifies that the actual value is positive.
|
S |
isStrictlyBetween(BigDecimal start,
BigDecimal end)
Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).
|
S |
isZero()
Verifies that the actual value is equal to zero.
|
S |
usingComparator(Comparator<? super BigDecimal> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
S |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
isEqualByComparingTo, isNotEqualByComparingTo
inBinary, inHexadecimal, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
isEqualToComparingFieldByField, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, withThreadDumpOnError
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
protected AbstractBigDecimalAssert(BigDecimal actual, Class<?> selfType)
public S isZero()
Example:
// assertion will pass
assertThat(BigDecimal.ZERO).isZero();
// assertion will fail
assertThat(new BigDecimal("8.00")).isZero();
isZero
in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
public S isNotZero()
Example:
// assertion will pass
assertThat(new BigDecimal("8.00")).isNotZero();
// assertion will fail
assertThat(BigDecimal.ZERO).isNotZero();
isNotZero
in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
public S isPositive()
Example:
// assertion will pass
assertThat(new BigDecimal("8.0")).isPositive();
// assertion will fail
assertThat(new BigDecimal("-8.0")).isPositive();
isPositive
in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
public S isNegative()
Example:
// assertion will pass
assertThat(new BigDecimal("-8.0")).isNegative();
// assertion will fail
assertThat(new BigDecimal("8.0")).isNegative();
isNegative
in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
public S isNotPositive()
Example:
// assertion will pass
assertThat(new BigDecimal("-8.0")).isNotPositive();
// assertion will fail
assertThat(new BigDecimal("8.0")).isNotPositive();
isNotPositive
in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
this
assertion object.public S isNotNegative()
Example:
// assertion will pass
assertThat(new BigDecimal("8.0")).isNotNegative();
// assertion will fail
assertThat(new BigDecimal("-8.0")).isNotNegative();
isNotNegative
in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
this
assertion object.public S 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 NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
start
- the start value (inclusive), expected not to be null.end
- the end value (inclusive), expected not to be null.public S 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 NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
start
- the start value (exclusive), expected not to be null.end
- the end value (exclusive), expected not to be null.public S 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 S isEqualByComparingTo(String expected)
isEqualByComparingTo(BigDecimal)
but takes care of converting given String to BigDecimal
for you.
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 S 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<S extends AbstractBigDecimalAssert<S>,BigDecimal>
usingComparator
in class AbstractComparableAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public S usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling Assert.usingComparator(Comparator)
.
usingDefaultComparator
in interface Assert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
usingDefaultComparator
in class AbstractComparableAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
this
assertion object.public S isCloseTo(BigDecimal other, 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")));
// BidDecimal 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")));
Copyright © 2013-2015 AssertJ. All Rights Reserved.