-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#235: Add matchers for Comparable
objects
#245
Conversation
Codecov Report
@@ Coverage Diff @@
## master #245 +/- ##
============================================
+ Coverage 98.95% 99.01% +0.06%
- Complexity 150 158 +8
============================================
Files 28 35 +7
Lines 383 407 +24
Branches 7 7
============================================
+ Hits 379 403 +24
Misses 4 4
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss here are a few comments
* @param <T> Underlying type. | ||
* @since 1.0.0 | ||
*/ | ||
public final class IsEqualTo<T extends Comparable<? super T>> extends |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss I'm not totally convinced by that name… especially because there is already a class named like this in hamcrest :/ maybe IsComparableTo
? It's not very good either to be honest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel IsComparableEqualTo
, IsComparableGreaterThan
, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss yep, I think it's not bad what you propose, a bit verbose but no ambiguity :) let's that! thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Done
* @param comparator The comparator. | ||
* @param expected The expected value | ||
*/ | ||
public IsEqualTo(final Comparator<T> comparator, final T expected) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss let's use Comparator<? super T>
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Done
/** | ||
* Comparator of numbers. | ||
*/ | ||
private static final Comparator<Number> FNC = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss instead of using a static field, let's have a normal field, a private constructor taking the Comparator<Number>
and the public constructor just delegates to it by building the actual Comparator
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Done.
|
||
@Override | ||
public String toString() { | ||
return "NumberComparator{}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss let's remove the {}
at the end of the string, or is it needed for some reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel This toString
is needed for the description, it cannot be disabled by hamcrest.
hamcrest/JavaHamcrest#344
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Done.
*/ | ||
final class NaturalOrderingTest { | ||
|
||
@MethodSource("arguments") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss for this kind of source of parameters, I would recommend using CsvSource if possible, just to have everything in one place and not rely on a string to know the name of a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Done
import org.hamcrest.comparator.ComparatorMatcherBuilder; | ||
|
||
/** | ||
* Is {@link Number} greater than or equal to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss this is not only about Number, right?
/** | ||
* Comparator of numbers. | ||
*/ | ||
private final transient Comparator<? super Number> comparator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss instead of making this transient, I think it's best to completely make this class non-serializable in practice (not sure why we need them to implement Serializable
actually), like we did here: https://github.com/yegor256/cactoos/pull/1587/files#diff-c061f133f1fcdb014d2fd2313288981a4af9ac71ca941c27e6f61b8e6c6fbdbeR38 because either way, objects of this class will never be serializable, but the way I propose seems simpler to understand since all the information is at the class annotations and not distributed in the class fields.
* @param <T> Underlying type. | ||
* @since 1.0.0 | ||
*/ | ||
public final class IsEqualTo<T extends Comparable<? super T>> extends |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreoss yep, I think it's not bad what you propose, a bit verbose but no ambiguity :) let's that! thx
@rultor merge |
@victornoel OK, I'll try to merge now. You can check the progress of the merge here |
@victornoel Done! FYI, the full log is here (took me 8min) |
Per #235