From 39e26354d100dc6d8125f0084641d4a09a51a825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20No=C3=ABl?= Date: Tue, 19 May 2020 20:48:11 +0200 Subject: [PATCH] (#1391) - Remove some more MatcherAssert --- .../java/org/cactoos/scalar/EqualityTest.java | 32 ++++++----- .../org/cactoos/scalar/FallbackFromTest.java | 21 ++++--- .../java/org/cactoos/scalar/FalseTest.java | 20 +++++-- .../org/cactoos/scalar/IoCheckedTest.java | 57 +++++++++++-------- .../java/org/cactoos/scalar/package-info.java | 8 +-- 5 files changed, 81 insertions(+), 57 deletions(-) diff --git a/src/test/java/org/cactoos/scalar/EqualityTest.java b/src/test/java/org/cactoos/scalar/EqualityTest.java index 57795c22ac..207f48073b 100644 --- a/src/test/java/org/cactoos/scalar/EqualityTest.java +++ b/src/test/java/org/cactoos/scalar/EqualityTest.java @@ -24,8 +24,8 @@ package org.cactoos.scalar; import org.cactoos.Bytes; -import org.hamcrest.MatcherAssert; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; import org.llorllale.cactoos.matchers.ScalarHasValue; /** @@ -38,62 +38,68 @@ public final class EqualityTest { @Test public void notEqualLeft() throws Exception { - MatcherAssert.assertThat( + new Assertion<>( + "Must compare smaller to greater", new Equality<>( new EqualityTest.Letters("A"), new EqualityTest.Letters("AB") ), new ScalarHasValue<>(-1) - ); + ).affirm(); } @Test public void notEqualRight() throws Exception { - MatcherAssert.assertThat( + new Assertion<>( + "Must compare greater to smaller", new Equality<>( new EqualityTest.Letters("AB"), new EqualityTest.Letters("A") ), new ScalarHasValue<>(1) - ); + ).affirm(); } @Test public void notEqualLeftWithSameSize() throws Exception { - MatcherAssert.assertThat( + new Assertion<>( + "Must compare smaller to smaller with same size", new Equality<>( new EqualityTest.Letters("A"), new EqualityTest.Letters("B") ), new ScalarHasValue<>(-1) - ); + ).affirm(); } @Test public void notEqualRightWithSameSize() throws Exception { - MatcherAssert.assertThat( + new Assertion<>( + "Must compare greater to smaller with same size", new Equality<>( new EqualityTest.Letters("B"), new EqualityTest.Letters("A") ), new ScalarHasValue<>(1) - ); + ).affirm(); } @Test public void equal() throws Exception { - MatcherAssert.assertThat( + new Assertion<>( + "Must compare equals", new Equality<>( new EqualityTest.Letters("A"), new EqualityTest.Letters("A") ), new ScalarHasValue<>(0) - ); + ).affirm(); } @Test public void compareEmptyArrays() throws Exception { - MatcherAssert.assertThat( + new Assertion<>( + "Must compare empty", new Equality<>( new EqualityTest.Letters(""), new EqualityTest.Letters("") ), new ScalarHasValue<>(0) - ); + ).affirm(); } /** diff --git a/src/test/java/org/cactoos/scalar/FallbackFromTest.java b/src/test/java/org/cactoos/scalar/FallbackFromTest.java index 01f02bc77e..bfc3142d18 100644 --- a/src/test/java/org/cactoos/scalar/FallbackFromTest.java +++ b/src/test/java/org/cactoos/scalar/FallbackFromTest.java @@ -26,9 +26,9 @@ import java.io.IOException; import java.util.IllegalFormatException; import org.cactoos.iterable.IterableOf; -import org.hamcrest.MatcherAssert; import org.hamcrest.core.IsEqual; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; /** * Test case for {@link FallbackFrom}. @@ -36,42 +36,41 @@ * @since 0.31 * @checkstyle JavadocMethodCheck (500 lines) */ -@SuppressWarnings("unchecked") public final class FallbackFromTest { @Test public void supportsException() { - MatcherAssert.assertThat( - "IOException class is not supported, but should be", + new Assertion<>( + "Must support IOException class", new FallbackFrom<>( new IterableOf<>(IOException.class), exp -> "IOException fallback" ).support(IOException.class), new IsEqual<>(0) - ); + ).affirm(); } @Test public void supportsInheritedException() { - MatcherAssert.assertThat( - "RuntimeException class is not supported, but should be", + new Assertion<>( + "Must support RuntimeException class", new FallbackFrom<>( new IterableOf<>(RuntimeException.class), exp -> "RuntimeException fallback #1" ).support(IllegalFormatException.class), new IsEqual<>(2) - ); + ).affirm(); } @Test public void doesNotSupportException() { - MatcherAssert.assertThat( - "RuntimeException class is supported, but should not be", + new Assertion<>( + "Must support RuntimeException class", new FallbackFrom<>( new IterableOf<>(RuntimeException.class), exp -> "RuntimeException fallback #2" ).support(ClassNotFoundException.class), new IsEqual<>(Integer.MIN_VALUE) - ); + ).affirm(); } } diff --git a/src/test/java/org/cactoos/scalar/FalseTest.java b/src/test/java/org/cactoos/scalar/FalseTest.java index 3423eddf64..6793ffdae8 100644 --- a/src/test/java/org/cactoos/scalar/FalseTest.java +++ b/src/test/java/org/cactoos/scalar/FalseTest.java @@ -23,9 +23,10 @@ */ package org.cactoos.scalar; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; +import org.hamcrest.core.IsEqual; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; +import org.llorllale.cactoos.matchers.ScalarHasValue; /** * Test case for {@link False}. @@ -37,10 +38,19 @@ public final class FalseTest { @Test public void asValue() throws Exception { - MatcherAssert.assertThat( + new Assertion<>( + "Must return false", new False().value(), - Matchers.equalTo(false) - ); + new IsEqual<>(false) + ).affirm(); } + @Test + public void asScalar() throws Exception { + new Assertion<>( + "Must be false", + new False(), + new ScalarHasValue<>(false) + ).affirm(); + } } diff --git a/src/test/java/org/cactoos/scalar/IoCheckedTest.java b/src/test/java/org/cactoos/scalar/IoCheckedTest.java index 0689a2fe78..00fe15379d 100644 --- a/src/test/java/org/cactoos/scalar/IoCheckedTest.java +++ b/src/test/java/org/cactoos/scalar/IoCheckedTest.java @@ -24,9 +24,9 @@ package org.cactoos.scalar; import java.io.IOException; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; +import org.llorllale.cactoos.matchers.Throws; /** * Test case for {@link IoChecked}. @@ -39,36 +39,45 @@ public final class IoCheckedTest { @Test public void rethrowsIoException() { final IOException exception = new IOException("intended"); - try { - new IoChecked<>( + new Assertion<>( + "Must rethrow IOException", + () -> new IoChecked<>( () -> { throw exception; } - ).value(); - } catch (final IOException ex) { - MatcherAssert.assertThat( - ex, Matchers.is(exception) - ); - } + ).value(), + new Throws<>("intended", IOException.class) + ).affirm(); } + @Test @SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes") - @Test(expected = IOException.class) - public void throwsException() throws Exception { - new IoChecked<>( - () -> { - throw new Exception("intended to fail"); - } - ).value(); + public void throwsException() { + new Assertion<>( + "Must throw IOException from Exception", + () -> new IoChecked<>( + () -> { + throw new Exception("intended to fail"); + } + ).value(), + new Throws<>(IOException.class) + ).affirm(); } - @Test(expected = IllegalStateException.class) - public void runtimeExceptionGoesOut() throws IOException { - new IoChecked<>( - () -> { - throw new IllegalStateException("intended to fail here"); - } - ).value(); + @Test + public void runtimeExceptionGoesOut() { + new Assertion<>( + "Must rethrow RuntimeExcepion", + () -> new IoChecked<>( + () -> { + throw new IllegalStateException("intended to fail here"); + } + ).value(), + new Throws<>( + "intended to fail here", + IllegalStateException.class + ) + ).affirm(); } } diff --git a/src/test/java/org/cactoos/scalar/package-info.java b/src/test/java/org/cactoos/scalar/package-info.java index 375b53ea54..6af123caf3 100644 --- a/src/test/java/org/cactoos/scalar/package-info.java +++ b/src/test/java/org/cactoos/scalar/package-info.java @@ -25,10 +25,10 @@ /** * Scalars, tests. * - * @todo #1389:30min Continue replacing usage of MatcherAssert.assertThat with - * Assertion from cactoos-matchers. Once there is no more usage of - * MatcherAssert.assertThat, add the signature of MatcherAssert.assertThat to - * forbidden-apis.txt + * @todo #1391:30min Continue replacing usage of MatcherAssert.assertThat with + * Assertion from cactoos-matchers in this package as well as in other packages. + * Once there is no more usage of MatcherAssert.assertThat, add the signature + * of MatcherAssert.assertThat to forbidden-apis.txt * @since 0.12 */ package org.cactoos.scalar;