Skip to content

Commit

Permalink
Replace the combination of IsNot and Matches with Mismatches #164
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier B. OURA committed Feb 22, 2021
1 parent dfcfa64 commit 267f3a4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
/**
* An extension of cactoos with object-oriented hamcrest matchers.
*
* @todo #136:30m Replace the combination of IsNot and Matches with Mismatches.
* This combination does not check textual output of Matcher, only boolean
* value. It's up for discussion if checking the output is too exhaustive or
* not, leave a comment to this task clarify that.
* @since 0.14
*/
package org.llorllale.cactoos.matchers;
4 changes: 2 additions & 2 deletions src/test/java/org/llorllale/cactoos/matchers/IsTrueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ void matchPositive() {
}

@Test
void describesCorrectly() {
void matchNegative() {
new Assertion<>(
"must throw an exception that describes the values",
"mismatches 'false'",
new IsTrue(),
new Mismatches<>(
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.cactoos.Func;
import org.cactoos.func.Repeated;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -83,8 +82,8 @@ void matchNegative() {
).affirm();
new Assertion<>(
"counter must not be incremented by all threads",
counter.get(),
new IsNot<>(new IsEqual<>(threads * attempts))
counter.get() < threads * attempts,
new IsEqual<>(true)
).affirm();
}

Expand Down
28 changes: 18 additions & 10 deletions src/test/java/org/llorllale/cactoos/matchers/ThrowsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.hamcrest.Description;
import org.hamcrest.StringDescription;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -72,7 +71,14 @@ void matchNegative() {
new Assertion<>(
"mismatches scalar that doesn't throw any exception",
new Throws<>("illegal arg", IllegalArgumentException.class),
new IsNot<>(new Matches<>(() -> "no exception"))
new Mismatches<>(
new ScalarOf<>(
() -> "no exception"
),
"Exception has type 'java.lang.IllegalArgumentException'"
+ " and message matches \"illegal arg\"",
"The exception wasn't thrown."
)
).affirm();
}

Expand All @@ -97,14 +103,16 @@ void mismatchException() {
// @checkstyle LineLength (1 line)
"mismatches if exception thrown is not subtype of expected exception",
new Throws<>("", IOException.class),
new IsNot<>(
new Matches<>(
new ScalarOf<>(
() -> {
throw new IllegalArgumentException("");
}
)
)
new Mismatches<>(
new ScalarOf<>(
() -> {
throw new IllegalArgumentException("");
}
),
"Exception has type 'java.io.IOException'"
+ " and message matches \"\"",
"Exception has type 'java.lang.IllegalArgumentException'"
+ " and message ''"
)
).affirm();
}
Expand Down

1 comment on commit 267f3a4

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 267f3a4 Feb 22, 2021

Choose a reason for hiding this comment

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

Puzzle 136-fc001f3f disappeared from src/main/java/org/llorllale/cactoos/matchers/package-info.java, that's why I closed #164. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.