Package org.assertj.core.internal
Class Comparables
- java.lang.Object
-
- org.assertj.core.internal.Comparables
-
- Direct Known Subclasses:
Characters
,Numbers
public class Comparables extends java.lang.Object
Reusable assertions for types that can be compared between each other, most of the time it means
s but also for type not implementingComparable
likeComparable
Number
(surprisingly not comparable).
-
-
Field Summary
Fields Modifier and Type Field Description private ComparisonStrategy
comparisonStrategy
(package private) Failures
failures
-
Constructor Summary
Constructors Constructor Description Comparables()
Build aComparables
using aStandardComparisonStrategy
.Comparables(ComparisonStrategy comparisonStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> boolean
areEqual(T actual, T expected)
<T> void
assertEqual(AssertionInfo info, T actual, T expected)
Asserts that two T instances are equal.<T> void
assertEqualByComparison(AssertionInfo info, java.lang.Comparable<? super 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> void
assertGreaterThan(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
private <T> void
assertGreaterThan(AssertionInfo info, java.lang.Comparable<? super T> actual, T other, TriFunction<java.lang.Comparable<? super T>,T,ComparisonStrategy,ErrorMessageFactory> errorMessageFactory)
Asserts that the actual value is greater than the other one.<T> void
assertGreaterThanOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
private <T> void
assertGreaterThanOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other, TriFunction<java.lang.Comparable<? super T>,T,ComparisonStrategy,ErrorMessageFactory> errorMessageFactory)
Asserts that the actual value is greater than or equal to the other one.<T> void
assertIsAfter(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
<T> void
assertIsAfterOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
<T> void
assertIsBefore(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
Asserts that the actual value is strictly before the other one.<T> void
assertIsBeforeOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
<T> void
assertIsBetween(AssertionInfo info, java.lang.Comparable<? super T> actual, T start, T end, boolean inclusiveStart, boolean inclusiveEnd)
Asserts that the actual value is between start and end, inclusive or not.<T> void
assertLessThan(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
Asserts that the actual value is less than the other one.private <T> void
assertLessThan(AssertionInfo info, java.lang.Comparable<? super T> actual, T other, TriFunction<java.lang.Comparable<? super T>,T,ComparisonStrategy,ErrorMessageFactory> errorMessageFactory)
Asserts that the actual value is less than the other one and throws an error with the given message factory.<T> void
assertLessThanOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
private <T> void
assertLessThanOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other, TriFunction<java.lang.Comparable<? super T>,T,ComparisonStrategy,ErrorMessageFactory> errorMessageFactory)
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> void
assertNotEqualByComparison(AssertionInfo info, java.lang.Comparable<? super 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)
private <T> void
checkBoundsValidity(T start, T end, boolean inclusiveStart, boolean inclusiveEnd)
boolean
equals(java.lang.Object obj)
java.util.Comparator<?>
getComparator()
int
hashCode()
private boolean
isGreaterThan(java.lang.Object actual, java.lang.Object other)
private <T> boolean
isLessThan(java.lang.Object actual, java.lang.Object other)
(package private) void
resetFailures()
(package private) void
setFailures(Failures failures)
java.lang.String
toString()
-
-
-
Field Detail
-
comparisonStrategy
private final ComparisonStrategy comparisonStrategy
-
failures
Failures failures
-
-
Constructor Detail
-
Comparables
public Comparables()
Build aComparables
using aStandardComparisonStrategy
.
-
Comparables
public Comparables(ComparisonStrategy comparisonStrategy)
-
-
Method Detail
-
getComparator
public java.util.Comparator<?> getComparator()
-
setFailures
void setFailures(Failures failures)
-
resetFailures
void resetFailures()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
assertEqual
public <T> void assertEqual(AssertionInfo info, T actual, T expected)
Asserts that two T instances are equal.- Type Parameters:
T
- the type of actual and expected- Parameters:
info
- contains information about the assertion.actual
- the actual value.expected
- the expected value.- Throws:
java.lang.AssertionError
- if the actual value isnull
.java.lang.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
public <T> void assertNotEqual(AssertionInfo info, T actual, T other)
Asserts that two T instances are not equal.- Type Parameters:
T
- the type of actual and expected- Parameters:
info
- contains information about the assertion.actual
- the actual value.other
- the value to compare the actual value to.- Throws:
java.lang.AssertionError
- if the actual value isnull
.java.lang.AssertionError
- if the actual value is equal to the other one.
-
assertEqualByComparison
public <T> void assertEqualByComparison(AssertionInfo info, java.lang.Comparable<? super 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:
java.lang.AssertionError
- if the actual value isnull
.java.lang.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> void assertNotEqualByComparison(AssertionInfo info, java.lang.Comparable<? super 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:
java.lang.AssertionError
- if the actual value isnull
.java.lang.AssertionError
- if the actual value is equal to the other one.
-
assertLessThan
public <T> void assertLessThan(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
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:
java.lang.AssertionError
- if the actual value isnull
.java.lang.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.
-
assertIsBefore
public <T> void assertIsBefore(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
Asserts that the actual value is strictly before 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:
java.lang.AssertionError
- if the actual value isnull
.java.lang.AssertionError
- if the actual value is not before the other one: this assertion will fail if the actual value is equal to or greater than the other value.
-
assertLessThan
private <T> void assertLessThan(AssertionInfo info, java.lang.Comparable<? super T> actual, T other, TriFunction<java.lang.Comparable<? super T>,T,ComparisonStrategy,ErrorMessageFactory> errorMessageFactory)
Asserts that the actual value is less than the other one and throws an error with the given message factory.- 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.errorMessageFactory
- the desired error message factory to generate the suitable error message- Throws:
java.lang.AssertionError
- if the actual value isnull
.java.lang.AssertionError
- if the actual value is not before the other one: this assertion will fail if the actual value is equal to or after the other value.
-
assertIsBeforeOrEqualTo
public <T> void assertIsBeforeOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
-
assertLessThanOrEqualTo
public <T> void assertLessThanOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
-
assertLessThanOrEqualTo
private <T> void assertLessThanOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other, TriFunction<java.lang.Comparable<? super T>,T,ComparisonStrategy,ErrorMessageFactory> errorMessageFactory)
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.errorMessageFactory
- the desired error message factory to generate the suitable error message- Throws:
java.lang.AssertionError
- if the actual value isnull
.java.lang.AssertionError
- if the actual value is greater than the other one.
-
assertIsAfter
public <T> void assertIsAfter(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
-
assertGreaterThan
public <T> void assertGreaterThan(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
-
assertGreaterThan
private <T> void assertGreaterThan(AssertionInfo info, java.lang.Comparable<? super T> actual, T other, TriFunction<java.lang.Comparable<? super T>,T,ComparisonStrategy,ErrorMessageFactory> errorMessageFactory)
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.errorMessageFactory
- the desired error message factory to generate the suitable error message- Throws:
java.lang.AssertionError
- if the actual value isnull
.java.lang.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
private boolean isGreaterThan(java.lang.Object actual, java.lang.Object other)
-
assertGreaterThanOrEqualTo
public <T> void assertGreaterThanOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
-
assertIsAfterOrEqualTo
public <T> void assertIsAfterOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other)
-
assertGreaterThanOrEqualTo
private <T> void assertGreaterThanOrEqualTo(AssertionInfo info, java.lang.Comparable<? super T> actual, T other, TriFunction<java.lang.Comparable<? super T>,T,ComparisonStrategy,ErrorMessageFactory> errorMessageFactory)
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.errorMessageFactory
- the desired error message factory to generate the suitable error message- Throws:
java.lang.AssertionError
- if the actual value isnull
.java.lang.AssertionError
- if the actual value is less than the other one.
-
isLessThan
private <T> boolean isLessThan(java.lang.Object actual, java.lang.Object other)
-
assertNotNull
protected static <T> void assertNotNull(AssertionInfo info, T actual)
-
assertIsBetween
public <T> void assertIsBetween(AssertionInfo info, java.lang.Comparable<? super 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:
java.lang.AssertionError
- if the actual value isnull
.java.lang.AssertionError
- if the actual value is not between start and end.java.lang.NullPointerException
- if start value isnull
.java.lang.NullPointerException
- if end value isnull
.java.lang.IllegalArgumentException
- if end value is less than start value.
-
checkBoundsValidity
private <T> void checkBoundsValidity(T start, T end, boolean inclusiveStart, boolean inclusiveEnd)
-
-