Package org.assertj.core.internal
Class Comparables
java.lang.Object
org.assertj.core.internal.Comparables
- Direct Known Subclasses:
Characters
,Numbers
Reusable assertions for
Comparable
s.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ComparisonStrategy
(package private) Failures
private static final Comparables
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> boolean
areEqual
(T actual, T expected) <T> void
assertEqual
(AssertionInfo info, T actual, T expected) Asserts that two T instances are equal.<T extends Comparable<? super T>>
voidassertEqualByComparison
(AssertionInfo info, T actual, T expected) Asserts that two
s are equal by invokingComparable
.Comparable.compareTo(Object)
Note that it does not rely on the customcomparisonStrategy
if one has been set.<T extends Comparable<? super T>>
voidassertGreaterThan
(AssertionInfo info, T actual, T other) Asserts that the actual value is greater than the other one.<T extends Comparable<? super T>>
voidassertGreaterThanOrEqualTo
(AssertionInfo info, T actual, T other) Asserts that the actual value is greater than or equal to the other one.<T extends Comparable<? super T>>
voidassertIsBetween
(AssertionInfo info, T actual, T start, T end, boolean inclusiveStart, boolean inclusiveEnd) Asserts that the actual value is between start and end, inclusive or not.<T extends Comparable<? super T>>
voidassertLessThan
(AssertionInfo info, T actual, T other) Asserts that the actual value is less than the other one.<T extends Comparable<? super T>>
voidassertLessThanOrEqualTo
(AssertionInfo info, T actual, T other) Asserts that the actual value is less than or equal to the other one.<T> void
assertNotEqual
(AssertionInfo info, T actual, T other) Asserts that two T instances are not equal.<T extends Comparable<? super T>>
voidassertNotEqualByComparison
(AssertionInfo info, T actual, T other) Asserts that two
s are not equal by invokingComparable
.Comparable.compareTo(Object)
Note that it does not rely on the customcomparisonStrategy
if one has been set.protected static <T> void
assertNotNull
(AssertionInfo info, T actual) Comparator<?>
static Comparables
instance()
Returns the singleton instance of this class based onStandardComparisonStrategy
.private boolean
isGreaterThan
(Object actual, Object other) delegates to {@link #comparisonStrategy#isGreaterThan(Object, Object)}private boolean
isLessThan
(Object actual, Object other) (package private) void
(package private) void
setFailures
(Failures failures)
-
Field Details
-
INSTANCE
-
failures
Failures failures -
comparisonStrategy
-
-
Constructor Details
-
Comparables
public Comparables() -
Comparables
-
-
Method Details
-
instance
Returns the singleton instance of this class based onStandardComparisonStrategy
.- Returns:
- the singleton instance of this class based on
StandardComparisonStrategy
.
-
getComparator
-
setFailures
-
resetFailures
void resetFailures() -
assertEqual
Asserts that two T instances are equal.- Parameters:
info
- contains information about the assertion.actual
- the actual value.expected
- the expected value.- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is not equal to the expected one. This method will throw aorg.junit.ComparisonFailure
instead if JUnit is in the classpath and the expected and actual values are not equal.
-
areEqual
protected <T> boolean areEqual(T actual, T expected) -
assertNotEqual
Asserts that two T instances are not equal.- Parameters:
info
- contains information about the assertion.actual
- the actual value.other
- the value to compare the actual value to.- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is equal to the other one.
-
assertEqualByComparison
public <T extends Comparable<? super T>> void assertEqualByComparison(AssertionInfo info, T actual, T expected) Asserts that two
s are equal by invokingComparable
.Comparable.compareTo(Object)
Note that it does not rely on the customcomparisonStrategy
if one has been set.- Type Parameters:
T
- used to guarantee that two objects of the same type are being compared against each other.- Parameters:
info
- contains information about the assertion.actual
- the actual value.expected
- the expected value.- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is not equal to the expected one. This method will throw aorg.junit.ComparisonFailure
instead if JUnit is in the classpath and the expected and actual values are not equal.
-
assertNotEqualByComparison
public <T extends Comparable<? super T>> void assertNotEqualByComparison(AssertionInfo info, T actual, T other) Asserts that two
s are not equal by invokingComparable
.Comparable.compareTo(Object)
Note that it does not rely on the customcomparisonStrategy
if one has been set.- Type Parameters:
T
- used to guarantee that two objects of the same type are being compared against each other.- Parameters:
info
- contains information about the assertion.actual
- the actual value.other
- the value to compare the actual value to.- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is equal to the other one.
-
assertLessThan
Asserts that the actual value is less than the other one.- Type Parameters:
T
- used to guarantee that two objects of the same type are being compared against each other.- Parameters:
info
- contains information about the assertion.actual
- the actual value.other
- the value to compare the actual value to.- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is not less than the other one: this assertion will fail if the actual value is equal to or greater than the other value.
-
assertLessThanOrEqualTo
public <T extends Comparable<? super T>> void assertLessThanOrEqualTo(AssertionInfo info, T actual, T other) Asserts that the actual value is less than or equal to the other one.- Type Parameters:
T
- used to guarantee that two objects of the same type are being compared against each other.- Parameters:
info
- contains information about the assertion.actual
- the actual value.other
- the value to compare the actual value to.- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is greater than the other one.
-
assertGreaterThan
public <T extends Comparable<? super T>> void assertGreaterThan(AssertionInfo info, T actual, T other) Asserts that the actual value is greater than the other one.- Type Parameters:
T
- used to guarantee that two objects of the same type are being compared against each other.- Parameters:
info
- contains information about the assertion.actual
- the actual value.other
- the value to compare the actual value to.- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is not greater than the other one: this assertion will fail if the actual value is equal to or less than the other value.
-
isGreaterThan
delegates to {@link #comparisonStrategy#isGreaterThan(Object, Object)} -
assertGreaterThanOrEqualTo
public <T extends Comparable<? super T>> void assertGreaterThanOrEqualTo(AssertionInfo info, T actual, T other) Asserts that the actual value is greater than or equal to the other one.- Type Parameters:
T
- used to guarantee that two objects of the same type are being compared against each other.- Parameters:
info
- contains information about the assertion.actual
- the actual value.other
- the value to compare the actual value to.- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is less than the other one.
-
isLessThan
-
assertNotNull
-
assertIsBetween
public <T extends Comparable<? super T>> void assertIsBetween(AssertionInfo info, T actual, T start, T end, boolean inclusiveStart, boolean inclusiveEnd) Asserts that the actual value is between start and end, inclusive or not.- Type Parameters:
T
- used to guarantee that two objects of the same type are being compared against each other.- Parameters:
info
- contains information about the assertion.actual
- the actual value.start
- the start value.end
- the end value.inclusiveStart
- if start is inclusive (fail is actual == start and inclusiveStart is false).inclusiveEnd
- if end is inclusive (fail is actual == end and inclusiveEnd is false).- Throws:
AssertionError
- if the actual value isnull
.AssertionError
- if the actual value is not between start and end.NullPointerException
- if start value isnull
.NullPointerException
- if end value isnull
.
-