From 787d25848956d3e01448d49d18a6f2e1a14d0b37 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 | 20 +++---- .../java/org/cactoos/scalar/FalseTest.java | 20 +++++-- .../org/cactoos/scalar/IoCheckedTest.java | 55 +++++++++++-------- .../java/org/cactoos/scalar/package-info.java | 8 +-- 5 files changed, 79 insertions(+), 56 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..8bca15603b 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}. @@ -41,37 +41,37 @@ public final class FallbackFromTest { @Test public void supportsException() { - MatcherAssert.assertThat( - "IOException class is not supported, but should be", + new Assertion<>( + "Must support exactly exception 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 inherited exception 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 not support unrelated exception 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..062187641c 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,43 @@ 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<>(exception.getMessage(), exception.getClass()) + ).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() { + final RuntimeException exception = new IllegalStateException("intended to fail here"); + new Assertion<>( + "Must rethrow RuntimeExcepion", + () -> new IoChecked<>( + () -> { + throw exception; + } + ).value(), + new Throws<>(exception.getMessage(), exception.getClass()) + ).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;