Skip to content
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

Merged
merged 14 commits into from May 15, 2021
Merged

Conversation

andreoss
Copy link
Contributor

@andreoss andreoss commented May 9, 2021

@codecov
Copy link

codecov bot commented May 9, 2021

Codecov Report

Merging #245 (b282a83) into master (37cac65) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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              
Impacted Files Coverage Δ Complexity Δ
...rg/llorllale/cactoos/matchers/MatcherEnvelope.java 100.00% <ø> (ø) 4.00 <0.00> (ø)
...lorllale/cactoos/matchers/IsComparableEqualTo.java 100.00% <100.00%> (ø) 2.00 <2.00> (?)
...lale/cactoos/matchers/IsComparableGreaterThan.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
...oos/matchers/IsComparableGreaterThanOrEqualTo.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
...orllale/cactoos/matchers/IsComparableLessThan.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
...actoos/matchers/IsComparableLessThanOrEqualTo.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
.../java/org/llorllale/cactoos/matchers/IsNumber.java 100.00% <100.00%> (ø) 1.00 <0.00> (-5.00)
...rg/llorllale/cactoos/matchers/NaturalOrdering.java 100.00% <100.00%> (ø) 3.00 <3.00> (?)
...g/llorllale/cactoos/matchers/NumberComparator.java 100.00% <100.00%> (ø) 4.00 <4.00> (?)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37cac65...b282a83. Read the comment docs.

@andreoss andreoss marked this pull request as ready for review May 9, 2021 03:14
@0crat
Copy link
Collaborator

0crat commented May 9, 2021

@victornoel/z everybody who has role REV is banned at #245; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)

Copy link
Collaborator

@victornoel victornoel left a 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
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@victornoel IsComparableEqualTo, IsComparableGreaterThan, etc?

Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param comparator The comparator.
* @param expected The expected value
*/
public IsEqualTo(final Comparator<T> comparator, final T expected) {
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* Comparator of numbers.
*/
private static final Comparator<Number> FNC =
Copy link
Collaborator

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.

Copy link
Contributor Author

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{}";
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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")
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import org.hamcrest.comparator.ComparatorMatcherBuilder;

/**
* Is {@link Number} greater than or equal to.
Copy link
Collaborator

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;
Copy link
Collaborator

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
Copy link
Collaborator

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

@victornoel
Copy link
Collaborator

@rultor merge

@rultor
Copy link
Collaborator

rultor commented May 15, 2021

@rultor merge

@victornoel OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 97d6832 into llorllale:master May 15, 2021
@rultor
Copy link
Collaborator

rultor commented May 15, 2021

@rultor merge

@victornoel Done! FYI, the full log is here (took me 8min)

@0crat
Copy link
Collaborator

0crat commented Jun 10, 2021

@victornoel/z everybody who has role REV is banned at #245; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)

@0crat 0crat removed the 0crat/scope label Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants