From 37cac65b66cba9b8a85657d48a0574c9598aaccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20No=C3=ABl?= Date: Sun, 2 May 2021 11:59:24 +0200 Subject: [PATCH] (#240) Exploit generic variance to improve user experience --- pom.xml | 2 +- .../java/org/llorllale/cactoos/matchers/Assertion.java | 4 ++-- .../java/org/llorllale/cactoos/matchers/HasEntry.java | 2 +- .../java/org/llorllale/cactoos/matchers/HasLines.java | 7 +++---- .../org/llorllale/cactoos/matchers/HasProperty.java | 2 +- .../java/org/llorllale/cactoos/matchers/HasValue.java | 4 ++-- .../java/org/llorllale/cactoos/matchers/HasValues.java | 4 ++-- .../llorllale/cactoos/matchers/HasValuesMatching.java | 4 ++-- .../org/llorllale/cactoos/matchers/IsApplicable.java | 4 ++-- .../java/org/llorllale/cactoos/matchers/IsEntry.java | 4 ++-- .../java/org/llorllale/cactoos/matchers/Matches.java | 7 +++---- .../org/llorllale/cactoos/matchers/MatchesBefore.java | 4 ++-- .../org/llorllale/cactoos/matchers/Mismatches.java | 10 ++++++---- .../org/llorllale/cactoos/matchers/RunsInThreads.java | 4 ++-- .../java/org/llorllale/cactoos/matchers/Throws.java | 4 ++-- 15 files changed, 33 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index e5d9e4e3..d5efcc3a 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ org.cactoos cactoos - 0.49 + 0.50 org.hamcrest diff --git a/src/main/java/org/llorllale/cactoos/matchers/Assertion.java b/src/main/java/org/llorllale/cactoos/matchers/Assertion.java index ef101069..0d3df7b5 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/Assertion.java +++ b/src/main/java/org/llorllale/cactoos/matchers/Assertion.java @@ -82,7 +82,7 @@ public final class Assertion { /** * Matcher. */ - private final Matcher matcher; + private final Matcher matcher; /** * Ctor. @@ -91,7 +91,7 @@ public final class Assertion { * @param matcher Tester. */ public Assertion( - final String msg, final T test, final Matcher matcher + final String msg, final T test, final Matcher matcher ) { this.msg = msg; this.test = test; diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java b/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java index 616afcb0..99d91040 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java @@ -49,7 +49,7 @@ * @param Type of value. * @since 1.0.0 */ -public final class HasEntry extends MatcherEnvelope> { +public final class HasEntry extends MatcherEnvelope> { /** * Ctor. * @param key The expected key. diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasLines.java b/src/main/java/org/llorllale/cactoos/matchers/HasLines.java index 3eb9ab79..973e7ca9 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasLines.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasLines.java @@ -41,7 +41,6 @@ * separator. * * @since 1.0.0 - * @checkstyle ProtectedMethodInFinalClassCheck (200 lines) */ public final class HasLines extends MatcherEnvelope { @@ -76,7 +75,7 @@ public HasLines(final Iterable lns) { * @param lns The expected lines to be present. */ public HasLines( - final BiFunc, Collection, Boolean> fnc, + final BiFunc, ? super Collection, Boolean> fnc, final Scalar sep, final Collection lns ) { @@ -96,9 +95,9 @@ public HasLines( * @param split The function to split the text which came for testing. */ private HasLines( - final BiFunc, Collection, Boolean> match, + final BiFunc, ? super Collection, Boolean> match, final Collection expected, - final Func> split + final Func> split ) { super( new MatcherOf<>( diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java b/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java index f942c02f..cd38fc6a 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java @@ -83,7 +83,7 @@ public HasProperty(final String key) { * * @param entr Entry matcher. */ - private HasProperty(final Matcher> entr) { + private HasProperty(final Matcher> entr) { super( new MatcherOf<>( properties -> new HasValuesMatching<>( diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasValue.java b/src/main/java/org/llorllale/cactoos/matchers/HasValue.java index 6dbcd551..55be59c7 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasValue.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasValue.java @@ -36,7 +36,7 @@ * @param Type of result * @since 0.2 */ -public final class HasValue extends MatcherEnvelope> { +public final class HasValue extends MatcherEnvelope> { /** * Ctor. @@ -50,7 +50,7 @@ public HasValue(final T value) { * Ctor. * @param mtr Matcher of the value */ - public HasValue(final Matcher mtr) { + public HasValue(final Matcher mtr) { super( new MatcherOf<>( scalar -> mtr.matches(scalar.value()), diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasValues.java b/src/main/java/org/llorllale/cactoos/matchers/HasValues.java index 2edc8744..18f6b1e3 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasValues.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasValues.java @@ -44,7 +44,7 @@ * @param Type of item. * @since 1.0.0 */ -public final class HasValues extends MatcherEnvelope> { +public final class HasValues extends MatcherEnvelope> { /** * Ctor. * @param expected The expected values within unit test. @@ -58,7 +58,7 @@ public HasValues(final X... expected) { * Ctor. * @param expected The expected values within unit test. */ - public HasValues(final Iterable expected) { + public HasValues(final Iterable expected) { super( new MatcherOf<>( actual -> new ListOf<>(actual).containsAll(new ListOf<>(expected)), diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java b/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java index 7c36bf64..ee2baa3e 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java @@ -45,13 +45,13 @@ * @param Type of item. * @since 1.0.0 */ -public final class HasValuesMatching extends MatcherEnvelope> { +public final class HasValuesMatching extends MatcherEnvelope> { /** * Ctor. * @param fnc The function to match at least one element within the * {@link Iterable}. */ - public HasValuesMatching(final Func fnc) { + public HasValuesMatching(final Func fnc) { super( new MatcherOf<>( actual -> new Or(fnc, actual).value(), diff --git a/src/main/java/org/llorllale/cactoos/matchers/IsApplicable.java b/src/main/java/org/llorllale/cactoos/matchers/IsApplicable.java index 3810e78f..6b42ed2f 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/IsApplicable.java +++ b/src/main/java/org/llorllale/cactoos/matchers/IsApplicable.java @@ -39,7 +39,7 @@ * @since 0.2 */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") -public final class IsApplicable extends MatcherEnvelope> { +public final class IsApplicable extends MatcherEnvelope> { /** * Ctor. @@ -55,7 +55,7 @@ public IsApplicable(final X inpt, final Y result) { * @param input Input for the function * @param mtr Matcher of the text */ - public IsApplicable(final X input, final Matcher mtr) { + public IsApplicable(final X input, final Matcher mtr) { super( new MatcherOf<>( func -> mtr.matches( diff --git a/src/main/java/org/llorllale/cactoos/matchers/IsEntry.java b/src/main/java/org/llorllale/cactoos/matchers/IsEntry.java index 340a5695..426ef42d 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/IsEntry.java +++ b/src/main/java/org/llorllale/cactoos/matchers/IsEntry.java @@ -40,7 +40,7 @@ * @param Type of value * @since 1.0.0 */ -public final class IsEntry extends MatcherEnvelope> { +public final class IsEntry extends MatcherEnvelope> { /** * Ctor. @@ -58,7 +58,7 @@ public IsEntry(final K key, final V value) { * @param key Matcher for key. * @param value Matcher for value. */ - public IsEntry(final Matcher key, final Matcher value) { + public IsEntry(final Matcher key, final Matcher value) { super( new MatcherOf<>( entry -> new And( diff --git a/src/main/java/org/llorllale/cactoos/matchers/Matches.java b/src/main/java/org/llorllale/cactoos/matchers/Matches.java index e7f136a0..f9c1ff98 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/Matches.java +++ b/src/main/java/org/llorllale/cactoos/matchers/Matches.java @@ -48,11 +48,10 @@ * * * @param Type of item. - * @param Type of tested matcher. * @since 1.0.0 * @checkstyle ProtectedMethodInFinalClassCheck (200 lines) */ -public final class Matches> extends TypeSafeMatcher { +public final class Matches extends TypeSafeMatcher> { /** * The testing arguments for the target matcher. @@ -74,12 +73,12 @@ public void describeTo(final Description desc) { } @Override - protected boolean matchesSafely(final M matcher) { + protected boolean matchesSafely(final Matcher matcher) { return matcher.matches(this.args); } @Override - protected void describeMismatchSafely(final M matcher, final Description dsc) { + protected void describeMismatchSafely(final Matcher matcher, final Description dsc) { matcher.describeTo(dsc); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java b/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java index 228d055b..a2eb8fa8 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java +++ b/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java @@ -67,14 +67,14 @@ public final class MatchesBefore extends TypeSafeDiagnosingMatcher { /** * The matcher. */ - private final Matcher matcher; + private final Matcher matcher; /** * Ctor. * @param mllsc Timeout. * @param mtchr Matcher. */ - public MatchesBefore(final long mllsc, final Matcher mtchr) { + public MatchesBefore(final long mllsc, final Matcher mtchr) { super(); this.millisec = mllsc; this.matcher = mtchr; diff --git a/src/main/java/org/llorllale/cactoos/matchers/Mismatches.java b/src/main/java/org/llorllale/cactoos/matchers/Mismatches.java index b1a12f7f..e44a7c84 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/Mismatches.java +++ b/src/main/java/org/llorllale/cactoos/matchers/Mismatches.java @@ -53,12 +53,11 @@ * } * * @param Type of item. - * @param Type of tested matcher. * @since 1.0.0 * @checkstyle ProtectedMethodInFinalClassCheck (200 lines) */ -public final class Mismatches> extends - TypeSafeDiagnosingMatcher { +public final class Mismatches extends + TypeSafeDiagnosingMatcher> { /** * Multiline start. @@ -140,7 +139,10 @@ public void describeTo(final Description desc) { } @Override - protected boolean matchesSafely(final M matcher, final Description dsc) { + protected boolean matchesSafely( + final Matcher matcher, + final Description dsc + ) { boolean mismatch; try { new Assertion<>("", this.args, matcher).affirm(); diff --git a/src/main/java/org/llorllale/cactoos/matchers/RunsInThreads.java b/src/main/java/org/llorllale/cactoos/matchers/RunsInThreads.java index b1a4cc13..216e0a08 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/RunsInThreads.java +++ b/src/main/java/org/llorllale/cactoos/matchers/RunsInThreads.java @@ -47,7 +47,7 @@ * @since 0.24 * @checkstyle JavadocMethodCheck (500 lines) */ -public final class RunsInThreads extends TypeSafeDiagnosingMatcher> { +public final class RunsInThreads extends TypeSafeDiagnosingMatcher> { /** * Input. @@ -88,7 +88,7 @@ public RunsInThreads(final T object, final int threads) { @Override public boolean matchesSafely( - final Func func, + final Func func, final Description desc ) { final ExecutorService service = Executors.newFixedThreadPool( diff --git a/src/main/java/org/llorllale/cactoos/matchers/Throws.java b/src/main/java/org/llorllale/cactoos/matchers/Throws.java index 1b9f4dfc..7856e483 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/Throws.java +++ b/src/main/java/org/llorllale/cactoos/matchers/Throws.java @@ -52,7 +52,7 @@ * @checkstyle ProtectedMethodInFinalClassCheck (200 lines) */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") -public final class Throws extends TypeSafeDiagnosingMatcher> { +public final class Throws extends TypeSafeDiagnosingMatcher> { /** * The expected exception message. @@ -109,7 +109,7 @@ public void describeTo(final Description dsc) { { "PMD.AvoidCatchingGenericException", "PMD.AvoidCatchingThrowable" } ) protected boolean matchesSafely( - final Scalar obj, + final Scalar obj, final Description dsc ) { // @checkstyle IllegalCatchCheck (20 lines)