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

(#164) Replace the combination of IsNot and Matches with Mismatches #233

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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