Skip to content

Commit

Permalink
(#133) Fixes Matches and Mismatches type arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
victornoel committed Sep 15, 2019
1 parent ba2e3bf commit 71b5871
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/llorllale/cactoos/matchers/Matches.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
* }</pre>
*
* @param <X> Type of item.
* @param <M> Type of tested matcher.
* @since 1.0.0
* @checkstyle ProtectedMethodInFinalClassCheck (200 lines)
*/
public final class Matches<X> extends TypeSafeDiagnosingMatcher<Matcher<X>> {
public final class Matches<X, M extends Matcher<X>> extends
TypeSafeDiagnosingMatcher<M> {

/**
* The testing arguments for the target matcher.
Expand All @@ -70,8 +72,7 @@ public void describeTo(final Description desc) {
}

@Override
protected boolean matchesSafely(final Matcher<X> matcher,
final Description dsc) {
protected boolean matchesSafely(final M matcher, final Description dsc) {
matcher.describeTo(dsc);
return matcher.matches(this.args);
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/llorllale/cactoos/matchers/Mismatches.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* }</pre>
*
* @param <X> Type of item.
* @param <M> Type of tested matcher.
* @since 1.0.0
* @todo #106:30min Convert all the Matcher tests to use Mismatches
* instead of checking directly the output of mismatch methods or
Expand All @@ -61,7 +62,8 @@
* working and throwing errors.
* @checkstyle ProtectedMethodInFinalClassCheck (200 lines)
*/
public final class Mismatches<X> extends TypeSafeDiagnosingMatcher<Matcher<X>> {
public final class Mismatches<X, M extends Matcher<X>> extends
TypeSafeDiagnosingMatcher<M> {

/**
* The testing arguments for the target matcher.
Expand Down Expand Up @@ -132,8 +134,7 @@ public void describeTo(final Description desc) {
// And then introduce some tests to validate that the description
// is properly constructed.
@Override
protected boolean matchesSafely(final Matcher<X> matcher,
final Description dsc) {
protected boolean matchesSafely(final M matcher, final Description dsc) {
boolean mismatch;
try {
new Assertion<>("", this.args, matcher).affirm();
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/llorllale/cactoos/matchers/MatchesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void matches() {
public void matchStatus() {
new Assertion<>(
"Matcher TextIs(abc) gives negative result for Text(def)",
new Matches<Text>(() -> "def").matches(new TextIs("abc")),
new Matches<>(new TextOf("def")).matches(new TextIs("abc")),
new IsEqual<>(false)
).affirm();
}
Expand All @@ -72,7 +72,7 @@ public void matchStatus() {
@Test
public void describeActual() {
final Description description = new StringDescription();
new Matches<Text>(new TextOf("expected")).matchesSafely(
new Matches<Text, TextIs>(new TextOf("expected")).matchesSafely(
new TextIs("actual"), description
);
new Assertion<>(
Expand All @@ -88,7 +88,7 @@ public void describeActual() {
@Test
public void describeExpected() {
final Description description = new StringDescription();
new Matches<Text>(new TextOf("expected")).describeTo(description);
new Matches<>(new TextOf("expected")).describeTo(description);
new Assertion<>(
"describes the expected value",
description.toString(),
Expand Down

0 comments on commit 71b5871

Please sign in to comment.