-
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8c85d1b
(#235) Add `NaturalOrdering` & `NumberComparator`
andreoss d0efdb9
(#235) Use `NaturalOrdering` in `IsNumber`
andreoss cf6c44e
(#235) Add `IsEqualTo`, `IsGreaterThan`, `IsLessThan` & etc.
andreoss c32a8fe
(#235) Fix indentation
andreoss 35a85c9
Generify `MatcherEnvelope`
andreoss dd76900
Use wildcard in `IsEqualTo`
andreoss a88c3c8
Pass `comparator` by ctor, instead of constant
andreoss b174616
Fix test
andreoss d7afd04
Remove redundat public modifier
andreoss b2744ce
Avoid MethodSource in tests
andreoss 363b291
Remove "{}" from toString
andreoss d63e09d
Suppres FindBugs warning
andreoss 22515d3
(#235) Add "Comparable" to class names to avoid collisions
andreoss b282a83
(#235) Fix typo
andreoss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/org/llorllale/cactoos/matchers/IsEqualTo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) for portions of project cactoos-matchers are held by | ||
* Yegor Bugayenko, 2017-2018, as part of project cactoos. | ||
* All other copyright for project cactoos-matchers are held by | ||
* George Aristy, 2018-2020. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.llorllale.cactoos.matchers; | ||
|
||
import java.util.Comparator; | ||
import org.hamcrest.comparator.ComparatorMatcherBuilder; | ||
|
||
/** | ||
* Is {@link Comparable} equal to. | ||
* | ||
* @param <T> Underlying type. | ||
* @since 1.0.0 | ||
*/ | ||
public final class IsEqualTo<T extends Comparable<? super T>> extends | ||
MatcherEnvelope<T> { | ||
/** | ||
* Ctor. | ||
* @param expected The expected value | ||
*/ | ||
public IsEqualTo(final T expected) { | ||
this(new NaturalOrdering<>(), expected); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param comparator The comparator. | ||
* @param expected The expected value | ||
*/ | ||
public IsEqualTo(final Comparator<? super T> comparator, final T expected) { | ||
super( | ||
ComparatorMatcherBuilder | ||
.comparedBy(comparator) | ||
.comparesEqualTo(expected) | ||
); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/org/llorllale/cactoos/matchers/IsGreaterThan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) for portions of project cactoos-matchers are held by | ||
* Yegor Bugayenko, 2017-2018, as part of project cactoos. | ||
* All other copyright for project cactoos-matchers are held by | ||
* George Aristy, 2018-2020. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.llorllale.cactoos.matchers; | ||
|
||
import org.hamcrest.comparator.ComparatorMatcherBuilder; | ||
|
||
/** | ||
* Is {@link Comparable} object greater than. | ||
* | ||
* @param <T> Underlying type. | ||
* @since 1.0.0 | ||
*/ | ||
public final class IsGreaterThan<T extends Comparable<? super T>> extends | ||
MatcherEnvelope<T> { | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param expected The expected value | ||
*/ | ||
public IsGreaterThan(final T expected) { | ||
super( | ||
ComparatorMatcherBuilder | ||
.comparedBy(new NaturalOrdering<T>()) | ||
.greaterThan(expected) | ||
); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/llorllale/cactoos/matchers/IsGreaterThanOrEqualTo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) for portions of project cactoos-matchers are held by | ||
* Yegor Bugayenko, 2017-2018, as part of project cactoos. | ||
* All other copyright for project cactoos-matchers are held by | ||
* George Aristy, 2018-2020. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.llorllale.cactoos.matchers; | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. @andreoss this is not only about Number, right? |
||
* | ||
* @param <T> Underlying type. | ||
* @since 1.0.0 | ||
*/ | ||
public final class IsGreaterThanOrEqualTo<T extends Comparable<? super T>> extends | ||
MatcherEnvelope<T> { | ||
/** | ||
* Ctor. | ||
* @param expected The expected value | ||
*/ | ||
public IsGreaterThanOrEqualTo(final T expected) { | ||
super( | ||
ComparatorMatcherBuilder | ||
.comparedBy(new NaturalOrdering<T>()) | ||
.greaterThanOrEqualTo(expected) | ||
); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/llorllale/cactoos/matchers/IsLessThan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) for portions of project cactoos-matchers are held by | ||
* Yegor Bugayenko, 2017-2018, as part of project cactoos. | ||
* All other copyright for project cactoos-matchers are held by | ||
* George Aristy, 2018-2020. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.llorllale.cactoos.matchers; | ||
|
||
import org.hamcrest.comparator.ComparatorMatcherBuilder; | ||
|
||
/** | ||
* Is {@link Comparable} object greater than. | ||
* | ||
* @param <T> Underlying type. | ||
* @since 1.0.0 | ||
*/ | ||
public final class IsLessThan<T extends Comparable<? super T>> extends | ||
MatcherEnvelope<T> { | ||
/** | ||
* Ctor. | ||
* @param expected The expected value | ||
*/ | ||
public IsLessThan(final T expected) { | ||
super( | ||
ComparatorMatcherBuilder | ||
.comparedBy(new NaturalOrdering<T>()) | ||
.lessThan(expected) | ||
); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/llorllale/cactoos/matchers/IsLessThanOrEqualTo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) for portions of project cactoos-matchers are held by | ||
* Yegor Bugayenko, 2017-2018, as part of project cactoos. | ||
* All other copyright for project cactoos-matchers are held by | ||
* George Aristy, 2018-2020. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.llorllale.cactoos.matchers; | ||
|
||
import org.hamcrest.comparator.ComparatorMatcherBuilder; | ||
|
||
/** | ||
* Is {@link Comparable} object less than or equal to. | ||
* | ||
* @param <T> Underlying type. | ||
* @since 1.0.0 | ||
*/ | ||
public final class IsLessThanOrEqualTo<T extends Comparable<? super T>> extends | ||
MatcherEnvelope<T> { | ||
/** | ||
* Ctor. | ||
* @param expected The expected value | ||
*/ | ||
public IsLessThanOrEqualTo(final T expected) { | ||
super( | ||
ComparatorMatcherBuilder | ||
.comparedBy(new NaturalOrdering<T>()) | ||
.lessThanOrEqualTo(expected) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 honestThere 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