Open ianbrandt opened 12 years ago
Hi Ian,
usingComparator
was made in the first place to compare objects with a strategy not based on equals
method (see this example).
Since usingComparator
is available for all Assert classes, adding isGreaterThan
and similar assertions will also be made available for all Assert classes.
This is when it gets tricky because we can use isGreaterThan
for objects that are non Comparable
which does not make sense :
// no garantee that a can be compared to b, so why would we allow this assertion ?
assertThat(a).isGreaterThan(b);
At this point, we can implement this feature with the following contract :
Comparable
, we consider isGreaterThan
assertion to be legalComparable
but usingComparator
has been called, we consider the previous assertion to be legal Comparable
and usingComparator
has not been called, we consider the previous assertion to be illegal and we would return an IllegalArgumentExceptionThe javadoc should clearly document this contract.
I think Comparable
related assertions can be a nice addition, the only drawback I see is the case when it can't work (non Comparable
object and no Comparator
provided) which can be misleading, but as we would fail with a clear error message, I think we can do it anyway.
I'm gonna ask other fest developers what their opinion is on this subject before doing anything.
Regards,
Joel
isGreaterThan and isLessThan exist only for Comparables, pretty much in assertions for numbers . I fail to understand why would you like to override the Comparable behavior with a Comparator. Please explain.
With 2.0M7 it seems I can write:
But not:
Nor:
Forgive me for not knowing anything about the FEST internals, but since all comparators return, "a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second" I would think these latter two methods would be possible.
For convenience
isGreaterThanOrEqualTo
andisLessThanOrEqualTo
would be an added bonus.