org.assertj.core.api
Class AbstractBigDecimalAssert<S extends AbstractBigDecimalAssert<S>>

java.lang.Object
  extended by org.assertj.core.api.AbstractAssert<S,A>
      extended by org.assertj.core.api.AbstractComparableAssert<S,A>
          extended by org.assertj.core.api.AbstractUnevenComparableAssert<S,BigDecimal>
              extended by org.assertj.core.api.AbstractBigDecimalAssert<S>
Type Parameters:
S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
All Implemented Interfaces:
Assert<S,BigDecimal>, ComparableAssert<S,BigDecimal>, Descriptable<S>, ExtensionPoints<S,BigDecimal>, NumberAssert<S,BigDecimal>, UnevenComparableAssert<S,BigDecimal>
Direct Known Subclasses:
BigDecimalAssert

public abstract class AbstractBigDecimalAssert<S extends AbstractBigDecimalAssert<S>>
extends AbstractUnevenComparableAssert<S,BigDecimal>
implements NumberAssert<S,BigDecimal>

Base class for all implementations of assertions for BigDecimals.

Author:
David DIDIER, Ted M. Young, Yvonne Wang, Alex Ruiz, Joel Costigliola, Mikhail Mazursky

Field Summary
 
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself
 
Constructor Summary
protected AbstractBigDecimalAssert(BigDecimal actual, Class<?> selfType)
           
 
Method Summary
 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.
 
Methods inherited from class org.assertj.core.api.AbstractUnevenComparableAssert
isEqualByComparingTo, isNotEqualByComparingTo
 
Methods inherited from class org.assertj.core.api.AbstractComparableAssert
inBinary, inHexadecimal, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
 
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, 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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.assertj.core.api.ComparableAssert
isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
 

Constructor Detail

AbstractBigDecimalAssert

protected AbstractBigDecimalAssert(BigDecimal actual,
                                   Class<?> selfType)
Method Detail

isZero

public S isZero()
Verifies that the actual value is equal to zero.

Example:

 // assertion will pass
 assertThat(BigDecimal.ZERO).isZero();
 
 // assertion will fail
 assertThat(new BigDecimal("8.00")).isZero();
 

Specified by:
isZero in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Returns:
this assertion object.

isNotZero

public S isNotZero()
Verifies that the actual value is not equal to zero.

Example:

 // assertion will pass
 assertThat(new BigDecimal("8.00")).isNotZero();
 
 // assertion will fail
 assertThat(BigDecimal.ZERO).isNotZero();
 

Specified by:
isNotZero in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Returns:
this assertion object.

isPositive

public S isPositive()
Verifies that the actual value is positive.

Example:

 // assertion will pass
 assertThat(new BigDecimal("8.0")).isPositive();
 
 // assertion will fail
 assertThat(new BigDecimal("-8.0")).isPositive();
 

Specified by:
isPositive in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Returns:
this assertion object.

isNegative

public S isNegative()
Verifies that the actual value is negative.

Example:

 // assertion will pass
 assertThat(new BigDecimal("-8.0")).isNegative();
 
 // assertion will fail
 assertThat(new BigDecimal("8.0")).isNegative();
 

Specified by:
isNegative in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Returns:
this assertion object.

isNotPositive

public S isNotPositive()
Verifies that the actual value is non positive (negative or equal zero).

Example:

 // assertion will pass
 assertThat(new BigDecimal("-8.0")).isNotPositive();
 
 // assertion will fail
 assertThat(new BigDecimal("8.0")).isNotPositive();
 

Specified by:
isNotPositive in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Returns:
this assertion object.

isNotNegative

public S isNotNegative()
Verifies that the actual value is non negative (positive or equal zero).

Example:

 // assertion will pass
 assertThat(new BigDecimal("8.0")).isNotNegative();
 
 // assertion will fail
 assertThat(new BigDecimal("-8.0")).isNotNegative();
 

Specified by:
isNotNegative in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Returns:
this assertion object.

isBetween

public S isBetween(BigDecimal start,
                   BigDecimal end)
Verifies that the actual value is in [start, end] range (start and end included).

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).

Specified by:
isBetween in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Parameters:
start - the start value (inclusive), expected not to be null.
end - the end value (inclusive), expected not to be null.
Returns:
this assertion object.

isStrictlyBetween

public S isStrictlyBetween(BigDecimal start,
                           BigDecimal end)
Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).

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"));
 

Specified by:
isStrictlyBetween in interface NumberAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Parameters:
start - the start value (exclusive), expected not to be null.
end - the end value (exclusive), expected not to be null.
Returns:
this assertion object.

isEqualTo

public S isEqualTo(String expected)
Same as 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");
 


isEqualByComparingTo

public S isEqualByComparingTo(String expected)
Same as 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");
 


usingComparator

public S usingComparator(Comparator<? super BigDecimal> customComparator)
Description copied from class: AbstractAssert
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.

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); 
 

Specified by:
usingComparator in interface Assert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Overrides:
usingComparator in class AbstractComparableAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Parameters:
customComparator - the comparator to use for incoming assertion checks.
Returns:
this assertion object.

usingDefaultComparator

public S usingDefaultComparator()
Description copied from class: AbstractAssert
Revert to standard comparison for incoming assertion checks.

This method should be used to disable a custom comparison strategy set by calling Assert.usingComparator(Comparator).

Specified by:
usingDefaultComparator in interface Assert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Overrides:
usingDefaultComparator in class AbstractComparableAssert<S extends AbstractBigDecimalAssert<S>,BigDecimal>
Returns:
this assertion object.

isCloseTo

public 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.

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.