Package org.assertj.core.internal
Class Comparables
java.lang.Object
org.assertj.core.internal.Comparables
- Direct Known Subclasses:
Characters,Numbers
Reusable assertions for types that can be compared between each other, most of the time it means
Comparables
but also for type not implementing Comparable like Number (surprisingly not comparable).- Author:
- Alex Ruiz, Joel Costigliola
-
Constructor Summary
ConstructorsConstructorDescriptionBuild aComparablesusing aStandardComparisonStrategy.Comparables(ComparisonStrategy comparisonStrategy) -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> booleanareEqual(T actual, T expected) <T> voidassertEqual(AssertionInfo info, T actual, T expected) Asserts that two T instances are equal.<T> voidassertEqualByComparison(AssertionInfo info, Comparable<? super T> actual, T expected) Asserts that twos are equal by invokingComparable.Comparable.compareTo(Object)
Note that it does not rely on the customcomparisonStrategyif one has been set.<T> voidassertGreaterThan(AssertionInfo info, Comparable<? super T> actual, T other) <T> voidassertGreaterThanOrEqualTo(AssertionInfo info, Comparable<? super T> actual, T other) <T> voidassertIsAfter(AssertionInfo info, Comparable<? super T> actual, T other) <T> voidassertIsAfterOrEqualTo(AssertionInfo info, Comparable<? super T> actual, T other) <T> voidassertIsBefore(AssertionInfo info, Comparable<? super T> actual, T other) Asserts that the actual value is strictly before the other one.<T> voidassertIsBeforeOrEqualTo(AssertionInfo info, Comparable<? super T> actual, T other) <T> voidassertIsBetween(AssertionInfo info, 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> voidassertLessThan(AssertionInfo info, Comparable<? super T> actual, T other) Asserts that the actual value is less than the other one.<T> voidassertLessThanOrEqualTo(AssertionInfo info, Comparable<? super T> actual, T other) <T> voidassertNotEqual(AssertionInfo info, T actual, T other) Asserts that two T instances are not equal.<T> voidassertNotEqualByComparison(AssertionInfo info, Comparable<? super T> actual, T other) Asserts that twos are not equal by invokingComparable.Comparable.compareTo(Object)
Note that it does not rely on the customcomparisonStrategyif one has been set.protected static <T> voidassertNotNull(AssertionInfo info, T actual) booleanComparator<?> inthashCode()toString()
-
Constructor Details
-
Comparables
public Comparables()Build aComparablesusing aStandardComparisonStrategy. -
Comparables
-
-
Method Details
-
getComparator
-
hashCode
public int hashCode() -
equals
-
toString
-
assertEqual
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:
AssertionError- if the actual value isnull.AssertionError- if the actual value is not equal to the expected one. This method will throw aorg.junit.ComparisonFailureinstead 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.- 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:
AssertionError- if the actual value isnull.AssertionError- if the actual value is equal to the other one.
-
assertEqualByComparison
public <T> void assertEqualByComparison(AssertionInfo info, Comparable<? super T> actual, T expected) Asserts that twos are equal by invokingComparable.Comparable.compareTo(Object)
Note that it does not rely on the customcomparisonStrategyif 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.ComparisonFailureinstead if JUnit is in the classpath and the expected and actual values are not equal.
-
assertNotEqualByComparison
public <T> void assertNotEqualByComparison(AssertionInfo info, Comparable<? super T> actual, T other) Asserts that twos are not equal by invokingComparable.Comparable.compareTo(Object)
Note that it does not rely on the customcomparisonStrategyif 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.
-
assertIsBefore
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:
AssertionError- if the actual value isnull.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.
-
assertIsBeforeOrEqualTo
-
assertLessThanOrEqualTo
-
assertIsAfter
-
assertGreaterThan
-
assertGreaterThanOrEqualTo
public <T> void assertGreaterThanOrEqualTo(AssertionInfo info, Comparable<? super T> actual, T other) -
assertIsAfterOrEqualTo
-
assertNotNull
-
assertIsBetween
public <T> void assertIsBetween(AssertionInfo info, 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:
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.IllegalArgumentException- if end value is less than start value.
-