public class Comparables
extends java.lang.Object
Comparables.| Modifier and Type | Field and Description |
|---|---|
private ComparisonStrategy |
comparisonStrategy |
(package private) Failures |
failures |
| Constructor and Description |
|---|
Comparables()
Build a
Comparables using a StandardComparisonStrategy. |
Comparables(ComparisonStrategy comparisonStrategy) |
| Modifier and Type | Method and 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 extends java.lang.Comparable<? super T>> |
assertEqualByComparison(AssertionInfo info,
T actual,
T expected)
Asserts that two
s are equal by invoking
.Note that it does not rely on the custom comparisonStrategy if one has been set. |
<T extends java.lang.Comparable<? super T>> |
assertGreaterThan(AssertionInfo info,
T actual,
T other)
Asserts that the actual value is greater than the other one.
|
<T extends java.lang.Comparable<? super T>> |
assertGreaterThanOrEqualTo(AssertionInfo info,
T actual,
T other)
Asserts that the actual value is greater than or equal to the other one.
|
<T extends java.lang.Comparable<? super T>> |
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.
|
<T extends java.lang.Comparable<? super T>> |
assertLessThan(AssertionInfo info,
T actual,
T other)
Asserts that the actual value is less than the other one.
|
<T extends java.lang.Comparable<? super T>> |
assertLessThanOrEqualTo(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 java.lang.Comparable<? super T>> |
assertNotEqualByComparison(AssertionInfo info,
T actual,
T other)
Asserts that two
s are not equal by invoking
.Note that it does not rely on the custom comparisonStrategy if one has been set. |
protected static <T> void |
assertNotNull(AssertionInfo info,
T actual) |
protected <T extends java.lang.Comparable<? super T>> |
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 boolean |
isLessThan(java.lang.Object actual,
java.lang.Object other) |
(package private) void |
resetFailures() |
(package private) void |
setFailures(Failures failures) |
java.lang.String |
toString() |
private final ComparisonStrategy comparisonStrategy
Failures failures
public Comparables()
Comparables using a StandardComparisonStrategy.public Comparables(ComparisonStrategy comparisonStrategy)
public java.util.Comparator<?> getComparator()
void setFailures(Failures failures)
void resetFailures()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic <T> void assertEqual(AssertionInfo info, T actual, T expected)
T - the type of actual and expectedinfo - contains information about the assertion.actual - the actual value.expected - the expected value.java.lang.AssertionError - if the actual value is null.java.lang.AssertionError - if the actual value is not equal to the expected one. This method will throw a
org.junit.ComparisonFailure instead if JUnit is in the classpath and the expected and actual
values are not equal.protected <T> boolean areEqual(T actual,
T expected)
public <T> void assertNotEqual(AssertionInfo info, T actual, T other)
T - the type of actual and expectedinfo - contains information about the assertion.actual - the actual value.other - the value to compare the actual value to.java.lang.AssertionError - if the actual value is null.java.lang.AssertionError - if the actual value is equal to the other one.public <T extends java.lang.Comparable<? super T>> void assertEqualByComparison(AssertionInfo info, T actual, T expected)
Comparables are equal by invoking
Comparable.compareTo(Object).comparisonStrategy if one has been set.T - used to guarantee that two objects of the same type are being compared against each other.info - contains information about the assertion.actual - the actual value.expected - the expected value.java.lang.AssertionError - if the actual value is null.java.lang.AssertionError - if the actual value is not equal to the expected one. This method will throw a
org.junit.ComparisonFailure instead if JUnit is in the classpath and the expected and actual
values are not equal.public <T extends java.lang.Comparable<? super T>> void assertNotEqualByComparison(AssertionInfo info, T actual, T other)
Comparables are not equal by invoking
Comparable.compareTo(Object) .comparisonStrategy if one has been set.T - used to guarantee that two objects of the same type are being compared against each other.info - contains information about the assertion.actual - the actual value.other - the value to compare the actual value to.java.lang.AssertionError - if the actual value is null.java.lang.AssertionError - if the actual value is equal to the other one.public <T extends java.lang.Comparable<? super T>> void assertLessThan(AssertionInfo info, T actual, T other)
T - used to guarantee that two objects of the same type are being compared against each other.info - contains information about the assertion.actual - the actual value.other - the value to compare the actual value to.java.lang.AssertionError - if the actual value is null.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.public <T extends java.lang.Comparable<? super T>> void assertLessThanOrEqualTo(AssertionInfo info, T actual, T other)
T - used to guarantee that two objects of the same type are being compared against each other.info - contains information about the assertion.actual - the actual value.other - the value to compare the actual value to.java.lang.AssertionError - if the actual value is null.java.lang.AssertionError - if the actual value is greater than the other one.public <T extends java.lang.Comparable<? super T>> void assertGreaterThan(AssertionInfo info, T actual, T other)
T - used to guarantee that two objects of the same type are being compared against each other.info - contains information about the assertion.actual - the actual value.other - the value to compare the actual value to.java.lang.AssertionError - if the actual value is null.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.private boolean isGreaterThan(java.lang.Object actual,
java.lang.Object other)
public <T extends java.lang.Comparable<? super T>> void assertGreaterThanOrEqualTo(AssertionInfo info, T actual, T other)
T - used to guarantee that two objects of the same type are being compared against each other.info - contains information about the assertion.actual - the actual value.other - the value to compare the actual value to.java.lang.AssertionError - if the actual value is null.java.lang.AssertionError - if the actual value is less than the other one.private boolean isLessThan(java.lang.Object actual,
java.lang.Object other)
protected static <T> void assertNotNull(AssertionInfo info, T actual)
public <T extends java.lang.Comparable<? super T>> void assertIsBetween(AssertionInfo info, T actual, T start, T end, boolean inclusiveStart, boolean inclusiveEnd)
T - used to guarantee that two objects of the same type are being compared against each other.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).java.lang.AssertionError - if the actual value is null.java.lang.AssertionError - if the actual value is not between start and end.java.lang.NullPointerException - if start value is null.java.lang.NullPointerException - if end value is null.java.lang.IllegalArgumentException - if end value is less than start value.protected <T extends java.lang.Comparable<? super T>> void checkBoundsValidity(T start,
T end,
boolean inclusiveStart,
boolean inclusiveEnd)