From c7bc081d723e78d088cc00c6022fc3b86860dd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20No=C3=ABl?= Date: Tue, 14 Jul 2020 11:31:16 +0200 Subject: [PATCH] (#135) - MatcherEnvelope is a real envelope, MatcherOf is complete --- .../cactoos/matchers/FuncApplies.java | 16 +- .../llorllale/cactoos/matchers/HasEntry.java | 32 ++-- .../llorllale/cactoos/matchers/HasLines.java | 8 +- .../cactoos/matchers/HasProperty.java | 21 +-- .../llorllale/cactoos/matchers/HasSize.java | 12 +- .../llorllale/cactoos/matchers/HasValues.java | 10 +- .../cactoos/matchers/HasValuesMatching.java | 16 +- .../cactoos/matchers/InputHasContent.java | 18 +- .../llorllale/cactoos/matchers/IsBlank.java | 8 +- .../llorllale/cactoos/matchers/IsEntry.java | 31 ++-- .../llorllale/cactoos/matchers/IsTrue.java | 8 +- .../cactoos/matchers/MatcherEnvelope.java | 44 ----- .../llorllale/cactoos/matchers/MatcherOf.java | 64 ++++++- .../cactoos/matchers/MatchesBefore.java | 14 +- .../cactoos/matchers/ScalarHasValue.java | 8 +- .../cactoos/matchers/MatcherEnvelopeTest.java | 169 ------------------ .../cactoos/matchers/MatcherOfTest.java | 21 +++ 17 files changed, 195 insertions(+), 305 deletions(-) delete mode 100644 src/test/java/org/llorllale/cactoos/matchers/MatcherEnvelopeTest.java diff --git a/src/main/java/org/llorllale/cactoos/matchers/FuncApplies.java b/src/main/java/org/llorllale/cactoos/matchers/FuncApplies.java index 8437222c..b8d46f00 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/FuncApplies.java +++ b/src/main/java/org/llorllale/cactoos/matchers/FuncApplies.java @@ -57,13 +57,15 @@ public FuncApplies(final X inpt, final Y result) { */ public FuncApplies(final X input, final Matcher mtr) { super( - func -> mtr.matches( - new UncheckedFunc<>(func).apply(input) - ), - desc -> desc.appendText("Func with ") - .appendDescriptionOf(mtr), - (func, desc) -> desc.appendText("Func with ") - .appendValue(func.apply(input)) + new MatcherOf<>( + func -> mtr.matches( + new UncheckedFunc<>(func).apply(input) + ), + desc -> desc.appendText("Func with ") + .appendDescriptionOf(mtr), + (func, desc) -> desc.appendText("Func with ") + .appendValue(func.apply(input)) + ) ); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java b/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java index 0c11d8f6..282473dd 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasEntry.java @@ -57,23 +57,25 @@ public final class HasEntry extends MatcherEnvelope> { @SuppressWarnings("PMD.AvoidDuplicateLiterals") public HasEntry(final K key, final V value) { super( - input -> Optional.ofNullable(input.get(key)) - .map(vl -> vl.equals(value)) - .orElse(false), - desc -> desc - .appendText("has entry ") - .appendValue(key) - .appendText("=") - .appendValue(value), - (input, desc) -> new Ternary<>( - () -> input.containsKey(key), - () -> desc.appendText("has entry ") + new MatcherOf<>( + input -> Optional.ofNullable(input.get(key)) + .map(vl -> vl.equals(value)) + .orElse(false), + desc -> desc + .appendText("has entry ") .appendValue(key) .appendText("=") - .appendValue(input.get(key)), - () -> desc.appendText("has no entry for ") - .appendValue(key) - ).value() + .appendValue(value), + (input, desc) -> new Ternary<>( + () -> input.containsKey(key), + () -> desc.appendText("has entry ") + .appendValue(key) + .appendText("=") + .appendValue(input.get(key)), + () -> desc.appendText("has no entry for ") + .appendValue(key) + ).value() + ) ); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasLines.java b/src/main/java/org/llorllale/cactoos/matchers/HasLines.java index 215665ed..9d8b02b4 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasLines.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasLines.java @@ -101,9 +101,11 @@ private HasLines( final Func> split ) { super( - actual -> match.apply(split.apply(actual), expected), - desc -> desc.appendText("Lines are ").appendValue(expected), - (actual, desc) -> desc.appendValue(split.apply(actual)) + new MatcherOf<>( + actual -> match.apply(split.apply(actual), expected), + desc -> desc.appendText("Lines are ").appendValue(expected), + (actual, desc) -> desc.appendValue(split.apply(actual)) + ) ); } diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java b/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java index 8cde9a4e..66833052 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasProperty.java @@ -84,16 +84,17 @@ public HasProperty(final String key) { */ private HasProperty(final Matcher> entr) { super( - // @checkstyle IndentationCheck (10 line) - properties -> new HasValuesMatching<>( - entr::matches - ).matches(properties.entrySet()), - desc -> desc - .appendText("has property ") - .appendDescriptionOf(entr), - (properties, desc) -> desc - .appendText("has properties ") - .appendValue(properties) + new MatcherOf<>( + properties -> new HasValuesMatching<>( + entr::matches + ).matches(properties.entrySet()), + desc -> desc + .appendText("has property ") + .appendDescriptionOf(entr), + (properties, desc) -> desc + .appendText("has properties ") + .appendValue(properties) + ) ); } diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasSize.java b/src/main/java/org/llorllale/cactoos/matchers/HasSize.java index 4d81f194..0f83c000 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasSize.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasSize.java @@ -42,11 +42,13 @@ public final class HasSize extends MatcherEnvelope> { */ public HasSize(final Integer size) { super( - input -> new LengthOf(input).intValue() == size, - desc -> desc.appendText("has size ") - .appendValue(size), - (input, desc) -> desc.appendText("has size ") - .appendValue(new LengthOf(input).intValue()) + new MatcherOf<>( + input -> new LengthOf(input).intValue() == size, + desc -> desc.appendText("has size ") + .appendValue(size), + (input, desc) -> desc.appendText("has size ") + .appendValue(new LengthOf(input).intValue()) + ) ); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasValues.java b/src/main/java/org/llorllale/cactoos/matchers/HasValues.java index f132bc94..7f30e63d 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasValues.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasValues.java @@ -59,10 +59,12 @@ public HasValues(final X... expected) { */ public HasValues(final Iterable expected) { super( - actual -> new ListOf<>(actual).containsAll(new ListOf<>(expected)), - desc -> desc.appendText("contains ") - .appendValue(new TextOf(expected)), - (actual, desc) -> desc.appendValue(new TextOf(actual)) + new MatcherOf<>( + actual -> new ListOf<>(actual).containsAll(new ListOf<>(expected)), + desc -> desc.appendText("contains ") + .appendValue(new TextOf(expected)), + (actual, desc) -> desc.appendValue(new TextOf(actual)) + ) ); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java b/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java index 9f4b1ad6..919960f8 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java +++ b/src/main/java/org/llorllale/cactoos/matchers/HasValuesMatching.java @@ -53,13 +53,15 @@ public final class HasValuesMatching extends MatcherEnvelope> { */ public HasValuesMatching(final Func fnc) { super( - actual -> new Or(fnc, actual).value(), - desc -> desc.appendText("The function matches at least 1 element."), - (actual, desc) -> desc.appendText( - new FormattedText( - "No any elements from [%s] matches by the function", - new TextOf(actual) - ).asString() + new MatcherOf<>( + actual -> new Or(fnc, actual).value(), + desc -> desc.appendText("The function matches at least 1 element."), + (actual, desc) -> desc.appendText( + new FormattedText( + "No any elements from [%s] matches by the function", + new TextOf(actual) + ).asString() + ) ) ); } diff --git a/src/main/java/org/llorllale/cactoos/matchers/InputHasContent.java b/src/main/java/org/llorllale/cactoos/matchers/InputHasContent.java index 8355873c..7830e59e 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/InputHasContent.java +++ b/src/main/java/org/llorllale/cactoos/matchers/InputHasContent.java @@ -69,15 +69,15 @@ public InputHasContent(final Text text) { */ public InputHasContent(final Matcher mtr) { super( - input -> mtr.matches( - new TextOf(input).asString() - ), - desc -> desc.appendText("has content ") - .appendDescriptionOf(mtr), - (input, desc) -> desc.appendText("has content ") - .appendValue( - new TextOf(input).asString() - ) + new MatcherOf<>( + input -> mtr.matches(new TextOf(input).asString()), + desc -> desc + .appendText("has content ") + .appendDescriptionOf(mtr), + (input, desc) -> desc + .appendText("has content ") + .appendValue(new TextOf(input).asString()) + ) ); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/IsBlank.java b/src/main/java/org/llorllale/cactoos/matchers/IsBlank.java index 255a4bdc..5cd4cda7 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/IsBlank.java +++ b/src/main/java/org/llorllale/cactoos/matchers/IsBlank.java @@ -37,9 +37,11 @@ public final class IsBlank extends MatcherEnvelope { */ public IsBlank() { super( - text -> text.trim().isEmpty(), - desc -> desc.appendText("is blank"), - (text, desc) -> desc.appendValue(text) + new MatcherOf<>( + text -> text.trim().isEmpty(), + desc -> desc.appendText("is blank"), + (text, desc) -> desc.appendValue(text) + ) ); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/IsEntry.java b/src/main/java/org/llorllale/cactoos/matchers/IsEntry.java index 47acd709..bca35936 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/IsEntry.java +++ b/src/main/java/org/llorllale/cactoos/matchers/IsEntry.java @@ -60,21 +60,22 @@ public IsEntry(final K key, final V value) { */ public IsEntry(final Matcher key, final Matcher value) { super( - // @checkstyle IndentationCheck (20 line) - entry -> new And( - () -> key.matches(entry.getKey()), - () -> value.matches(entry.getValue()) - ).value(), - desc -> { - IsEntry.descriptionOfKey(desc).appendDescriptionOf(key); - IsEntry.descriptionOfValue(desc).appendDescriptionOf(value); - }, - (entry, desc) -> { - IsEntry.descriptionOfKey(desc); - key.describeMismatch(entry.getKey(), desc); - IsEntry.descriptionOfValue(desc); - value.describeMismatch(entry.getValue(), desc); - } + new MatcherOf<>( + entry -> new And( + () -> key.matches(entry.getKey()), + () -> value.matches(entry.getValue()) + ).value(), + desc -> { + IsEntry.descriptionOfKey(desc).appendDescriptionOf(key); + IsEntry.descriptionOfValue(desc).appendDescriptionOf(value); + }, + (entry, desc) -> { + IsEntry.descriptionOfKey(desc); + key.describeMismatch(entry.getKey(), desc); + IsEntry.descriptionOfValue(desc); + value.describeMismatch(entry.getValue(), desc); + } + ) ); } diff --git a/src/main/java/org/llorllale/cactoos/matchers/IsTrue.java b/src/main/java/org/llorllale/cactoos/matchers/IsTrue.java index 8ac70f44..79c12c20 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/IsTrue.java +++ b/src/main/java/org/llorllale/cactoos/matchers/IsTrue.java @@ -37,9 +37,11 @@ public final class IsTrue extends MatcherEnvelope { */ public IsTrue() { super( - bool -> bool, - desc -> desc.appendValue(true), - (bool, desc) -> desc.appendValue(bool) + new MatcherOf<>( + bool -> bool, + desc -> desc.appendValue(true), + (bool, desc) -> desc.appendValue(bool) + ) ); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/MatcherEnvelope.java b/src/main/java/org/llorllale/cactoos/matchers/MatcherEnvelope.java index e5b6eb3f..41ea5abd 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/MatcherEnvelope.java +++ b/src/main/java/org/llorllale/cactoos/matchers/MatcherEnvelope.java @@ -26,12 +26,6 @@ */ package org.llorllale.cactoos.matchers; -import org.cactoos.BiProc; -import org.cactoos.Func; -import org.cactoos.Proc; -import org.cactoos.func.UncheckedBiProc; -import org.cactoos.func.UncheckedFunc; -import org.cactoos.func.UncheckedProc; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; @@ -40,9 +34,6 @@ * Matcher Envelope. * @param The type of the Matcher. * @since 1.0.0 - * @todo #129:30min Refactor other matchers to extend MatcherEnvelope. - * If you do not know how to do it please refer to InputHasContent - * class as the example. */ public abstract class MatcherEnvelope extends TypeSafeMatcher { @@ -51,41 +42,6 @@ public abstract class MatcherEnvelope extends TypeSafeMatcher { */ private final Matcher origin; - /** - * Ctor. - * @param match Function matches an actual object with expected one - * @param description Procedure generates a description of the object - * @param mismatch BiProcedure generates a description for situation when an - * actual object does not match to the expected one - */ - protected MatcherEnvelope( - final Func match, - final Proc description, - final BiProc mismatch - ) { - this( - new TypeSafeMatcher() { - @Override - public void describeTo(final Description desc) { - new UncheckedProc<>(description).exec(desc); - } - - @Override - protected void describeMismatchSafely( - final T item, - final Description desc - ) { - new UncheckedBiProc<>(mismatch).exec(item, desc); - } - - @Override - protected boolean matchesSafely(final T item) { - return new UncheckedFunc<>(match).apply(item); - } - } - ); - } - /** * Ctor. * @param origin Encapsulated matcher. diff --git a/src/main/java/org/llorllale/cactoos/matchers/MatcherOf.java b/src/main/java/org/llorllale/cactoos/matchers/MatcherOf.java index 5d964f96..6e7c4d28 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/MatcherOf.java +++ b/src/main/java/org/llorllale/cactoos/matchers/MatcherOf.java @@ -26,12 +26,18 @@ */ package org.llorllale.cactoos.matchers; +import org.cactoos.BiProc; import org.cactoos.Func; import org.cactoos.Proc; import org.cactoos.Text; import org.cactoos.func.FuncOf; +import org.cactoos.func.UncheckedBiProc; +import org.cactoos.func.UncheckedFunc; +import org.cactoos.func.UncheckedProc; import org.cactoos.text.FormattedText; import org.cactoos.text.UncheckedText; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; /** * Func as Matcher. @@ -40,8 +46,27 @@ * * @param Type of object to match * @since 0.12 + * @todo #135:30min Remove all constructors except the last one so that + * every matcher implemented using MatcherOf take care of properly + * describe itself and the mismatch. */ -public final class MatcherOf extends MatcherEnvelope { +public final class MatcherOf extends TypeSafeMatcher { + + /** + * Matches an actual object with expected one. + */ + private final Func match; + + /** + * Generates a description of the object. + */ + private final Proc description; + + /** + * Generates a description for situation when an actual + * object does not match to the expected one. + */ + private final BiProc mismatch; /** * Ctor. @@ -65,7 +90,7 @@ public MatcherOf(final Func fnc) { * @param description The description */ public MatcherOf(final Func fnc, final Text description) { - super( + this( fnc, desc -> desc.appendText( new FormattedText("\"%s\"", description).asString() @@ -73,4 +98,39 @@ public MatcherOf(final Func fnc, final Text description) { (actual, desc) -> desc.appendValue(actual) ); } + + /** + * Ctor. + * @param match Matches an actual object with expected one + * @param description Generates a description of the object + * @param mismatch Generates a description for situation when an + * actual object does not match to the expected one + */ + public MatcherOf( + final Func match, + final Proc description, + final BiProc mismatch + ) { + this.match = match; + this.description = description; + this.mismatch = mismatch; + } + + @Override + public void describeTo(final Description desc) { + new UncheckedProc<>(this.description).exec(desc); + } + + @Override + public void describeMismatchSafely( + final T item, + final Description desc + ) { + new UncheckedBiProc<>(this.mismatch).exec(item, desc); + } + + @Override + public boolean matchesSafely(final T item) { + return new UncheckedFunc<>(this.match).apply(item); + } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java b/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java index 79befdda..57f88007 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java +++ b/src/main/java/org/llorllale/cactoos/matchers/MatchesBefore.java @@ -56,12 +56,14 @@ public final class MatchesBefore extends MatcherEnvelope { */ public MatchesBefore(final long millisec, final Matcher matcher) { super( - new Timed<>(matcher::matches, millisec), - desc -> desc - .appendDescriptionOf(matcher) - .appendText(" runs in less than ") - .appendValue(millisec).appendText(" milliseconds"), - matcher::describeMismatch + new MatcherOf<>( + new Timed<>(matcher::matches, millisec), + desc -> desc + .appendDescriptionOf(matcher) + .appendText(" runs in less than ") + .appendValue(millisec).appendText(" milliseconds"), + matcher::describeMismatch + ) ); } } diff --git a/src/main/java/org/llorllale/cactoos/matchers/ScalarHasValue.java b/src/main/java/org/llorllale/cactoos/matchers/ScalarHasValue.java index d20115c5..8622f3cb 100644 --- a/src/main/java/org/llorllale/cactoos/matchers/ScalarHasValue.java +++ b/src/main/java/org/llorllale/cactoos/matchers/ScalarHasValue.java @@ -52,9 +52,11 @@ public ScalarHasValue(final T value) { */ public ScalarHasValue(final Matcher mtr) { super( - scalar -> mtr.matches(scalar.value()), - desc -> desc.appendText("Scalar with ").appendDescriptionOf(mtr), - (scalar, desc) -> mtr.describeMismatch(scalar.value(), desc) + new MatcherOf<>( + scalar -> mtr.matches(scalar.value()), + desc -> desc.appendText("Scalar with ").appendDescriptionOf(mtr), + (scalar, desc) -> mtr.describeMismatch(scalar.value(), desc) + ) ); } } diff --git a/src/test/java/org/llorllale/cactoos/matchers/MatcherEnvelopeTest.java b/src/test/java/org/llorllale/cactoos/matchers/MatcherEnvelopeTest.java deleted file mode 100644 index d0ef45c5..00000000 --- a/src/test/java/org/llorllale/cactoos/matchers/MatcherEnvelopeTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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. - * - * 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.cactoos.BiProc; -import org.cactoos.Func; -import org.cactoos.Proc; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; -import org.hamcrest.core.StringContains; -import org.junit.Test; - -/** - * Test case for {@link MatcherEnvelope}. - * - * @since 1.0.0 - */ -public final class MatcherEnvelopeTest { - - /** - * Test integer to use in tests. - */ - private static final Integer TEST_INTEGER = 42; - - /** - * Test string to use in tests. - */ - private static final String TEST_STRING = "TestString"; - - /** - * Tests that MatcherEnvelope delegates matchesSafely to the encapsulated - * matcher. Uses one-argument constructor of MatcherEnvelope. - */ - @Test - public void decoratesMatchesSafely() { - new Assertion<>( - "must delegate match to encapsulated matcher", - MatcherEnvelopeTest.TEST_INTEGER, - new MatcherEnvelopeChild<>(new EncapsulatedTestMatcher()) - ).affirm(); - } - - /** - * Tests that MatcherEnvelope delegates describeTo to the encapsulated - * matcher. Uses one-argument constructor of MatcherEnvelope. - */ - @Test - public void decoratesDescribeTo() { - new Assertion<>( - "must throw an AssertionError containing TEST_INTEGER", - () -> { - new Assertion<>( - "must delegate describeTo to encapsulated matcher", - MatcherEnvelopeTest.TEST_INTEGER + 1, - new MatcherEnvelopeChild<>(new EncapsulatedTestMatcher()) - ).affirm(); - return true; - }, - new Throws<>( - new StringContains(MatcherEnvelopeTest.TEST_INTEGER.toString()), - AssertionError.class - ) - ).affirm(); - } - - /** - * Tests that MatcherEnvelope delegates describeMismatchSafely to the - * encapsulated matcher. Uses multi-argument constructor of - * MatcherEnvelope. - */ - @Test - public void decoratesDescribeMismatchSafely() { - new Assertion<>( - "must throw an AssertionError containing TEST_STRING", - () -> { - new Assertion<>( - // @checkstyle LineLength (1 line) - "must delegate describeMismatchSafely to encapsulated matcher", - MatcherEnvelopeTest.TEST_INTEGER, - new MatcherEnvelopeChild<>( - item -> false, - description -> { }, - (item, description) -> description.appendText( - MatcherEnvelopeTest.TEST_STRING - ) - ) - ).affirm(); - return true; - }, - new Throws<>( - new StringContains(MatcherEnvelopeTest.TEST_STRING), - AssertionError.class - ) - ).affirm(); - } - - /** - * Private child class to test MatcherEnvelope, which is abstract. - * @param Type of object under the test. - * @since 1.0.0 - */ - private static class MatcherEnvelopeChild extends MatcherEnvelope { - - /** - * Multi-argument constructor, just delegating to super. - * @param match Function matches an actual object with expected one - * @param description Procedure generates a description of the object - * @param mismatch BiProcedure generates a description for situation - * when an actual object does not match to the expected one - */ - MatcherEnvelopeChild( - final Func match, - final Proc description, - final BiProc mismatch - ) { - super(match, description, mismatch); - } - - /** - * One-argument constructor, just delegating to super. - * @param origin Matcher to encapsulate - */ - MatcherEnvelopeChild(final Matcher origin) { - super(origin); - } - } - - /** - * Test matcher to test one-argument constructor of MatcherEnvelope. - * @since 1.0.0 - */ - private static class EncapsulatedTestMatcher extends TypeSafeMatcher { - @Override - public void describeTo(final Description description) { - description.appendValue(MatcherEnvelopeTest.TEST_INTEGER); - } - - @Override - protected boolean matchesSafely(final Integer integer) { - return integer.equals(MatcherEnvelopeTest.TEST_INTEGER); - } - } -} diff --git a/src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java b/src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java index 2c1868f0..65719be5 100644 --- a/src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java +++ b/src/test/java/org/llorllale/cactoos/matchers/MatcherOfTest.java @@ -27,6 +27,7 @@ package org.llorllale.cactoos.matchers; import org.cactoos.text.FormattedText; +import org.cactoos.text.Joined; import org.cactoos.text.TextOf; import org.cactoos.text.UncheckedText; import org.hamcrest.core.IsNot; @@ -40,6 +41,7 @@ * @since 1.0.0 * @checkstyle JavadocMethodCheck (500 lines) * @checkstyle MagicNumberCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ public final class MatcherOfTest { @@ -93,4 +95,23 @@ public void matcherOfProcMatchesAnyArguments() { new Matches<>("a") ).affirm(); } + + @Test + public void mismatches() { + final Integer expected = 42; + final Integer provided = 43; + new Assertion<>( + "must mismatches correctly", + new MatcherOf<>( + input -> input.equals(expected), + desc -> desc.appendValue(expected), + (actual, desc) -> desc.appendValue(actual) + ), + new Mismatches<>( + provided, + new Joined("", "<", expected.toString(), ">"), + new Joined("", "<", provided.toString(), ">") + ) + ).affirm(); + } }