S - the "self" type of this assertion class. Please read "Emulating
'self types' using Java Generics to simplify fluent API implementation" for more details.A - the type of the "actual" value.public interface NumberAssert<S extends NumberAssert<S,A>,A extends Number>
Numbers.| Modifier and Type | Method and Description |
|---|---|
S |
isBetween(A start,
A end)
Verifies that the actual value is in [start, end] range (start included, end included).
|
S |
isCloseTo(A expected,
Offset<A> 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 |
isCloseTo(A 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. |
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(A start,
A 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 isZero()
Example:
// assertions will pass
assertThat(0).isZero();
assertThat(0.0).isZero();
// assertions will fail
assertThat(42).isZero();
assertThat(3.142).isZero();AssertionError - if the actual value is null.AssertionError - if the actual value is not equal to zero.S isNotZero()
Example:
// assertions will pass
assertThat(42).isNotZero();
assertThat(3.142).isNotZero();
// assertions will fail
assertThat(0).isNotZero();
assertThat(0.0).isNotZero();AssertionError - if the actual value is null.AssertionError - if the actual value is equal to zero.S isPositive()
Example:
// assertions will pass
assertThat(42).isPositive();
assertThat(3.142).isPositive();
// assertions will fail
assertThat(0).isPositive();
assertThat(-42).isPositive();AssertionError - if the actual value is null.AssertionError - if the actual value is not positive.S isNegative()
Example:
// assertions will pass
assertThat(-42).isNegative();
assertThat(-3.124).isNegative();
// assertions will fail
assertThat(0).isNegative();
assertThat(42).isNegative();AssertionError - if the actual value is null.AssertionError - if the actual value is not negative.S isNotNegative()
Example:
// assertions will pass
assertThat(42).isNotNegative();
assertThat(0).isNotNegative();
// assertions will fail
assertThat(-42).isNotNegative();
assertThat(-3.124).isNotNegative();this assertion object.AssertionError - if the actual value is null.AssertionError - if the actual value is not non negative.S isNotPositive()
Example:
// assertions will pass
assertThat(-42).isNotPositive();
assertThat(0).isNotPositive();
// assertions will fail
assertThat(42).isNotPositive();
assertThat(3.124).isNotPositive();this assertion object.AssertionError - if the actual value is null.AssertionError - if the actual value is not non positive.S isBetween(A start, A end)
Example:
// these assertions succeed ...
assertThat(12).isBetween(10, 14);
assertThat(12).isBetween(12, 14);
assertThat(12).isBetween(10, 12);
// ... but this one fails
assertThat(12).isBetween(14, 16);start - the start value (inclusive), expected not to be null.end - the end value (inclusive), expected not to be null.AssertionError - if the actual value is null.NullPointerException - if start value is null.NullPointerException - if end value is null.AssertionError - if the actual value is not in [start, end] range.S isStrictlyBetween(A start, A end)
Example:
// this assertion succeeds ...
assertThat(12).isStrictlyBetween(10, 14);
// ... but these ones fail
assertThat(12).isStrictlyBetween(12, 14);
assertThat(12).isStrictlyBetween(10, 12);
assertThat(12).isStrictlyBetween(16, 18);start - the start value (exclusive), expected not to be null.end - the end value (exclusive), expected not to be null.AssertionError - if the actual value is null.NullPointerException - if start value is null.NullPointerException - if end value is null.AssertionError - if the actual value is not in ]start, end[ range.S isCloseTo(A expected, Offset<A> offset)
Example with double:
// assertions will pass:
assertThat(8.1).isCloseTo(8.0, within(0.2));
// you can use offset if you prefer
assertThat(8.1).isCloseTo(8.0, offset(0.2));
// if difference is exactly equals to the offset (0.1), it's ok
assertThat(8.1).isCloseTo(8.0, within(0.1));
// assertion will fail
assertThat(8.1).isCloseTo(8.0, within(0.01));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 equal to the given one.S isCloseTo(A expected, Percentage percentage)
Example with double:
// assertions will pass:
assertThat(11.0).isCloseTo(10.0, withinPercentage(20));
// if difference is exactly equals to the computed offset (1.0), it's ok
assertThat(11.0).isCloseTo(10.0, withinPercentage(10));
// assertion will fail
assertThat(11.0).isCloseTo(10.0, withinPercentage(5));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 equal to the given one.Copyright © 2013–2016 AssertJ. All rights reserved.