diff --git a/src/main/java/org/cactoos/iterable/IterableOf.java b/src/main/java/org/cactoos/iterable/IterableOf.java index 99c4ae3c87..c5bab0dbd3 100644 --- a/src/main/java/org/cactoos/iterable/IterableOf.java +++ b/src/main/java/org/cactoos/iterable/IterableOf.java @@ -32,13 +32,11 @@ import org.cactoos.iterator.IteratorOf; import org.cactoos.scalar.And; import org.cactoos.scalar.FallbackFrom; -import org.cactoos.scalar.False; import org.cactoos.scalar.Folded; import org.cactoos.scalar.Or; import org.cactoos.scalar.ScalarWithFallback; import org.cactoos.scalar.Sticky; import org.cactoos.scalar.SumOfInt; -import org.cactoos.scalar.True; import org.cactoos.scalar.Unchecked; import org.cactoos.text.TextOf; import org.cactoos.text.UncheckedText; diff --git a/src/main/java/org/cactoos/list/Shuffled.java b/src/main/java/org/cactoos/list/Shuffled.java index e7cef45eab..aad6b22c94 100644 --- a/src/main/java/org/cactoos/list/Shuffled.java +++ b/src/main/java/org/cactoos/list/Shuffled.java @@ -24,7 +24,6 @@ package org.cactoos.list; import java.util.Collections; -import java.util.List; /** * Shuffled list. diff --git a/src/test/java/org/cactoos/func/FuncWithFallbackTest.java b/src/test/java/org/cactoos/func/FuncWithFallbackTest.java index 8c2f3bf3ad..0a39880876 100644 --- a/src/test/java/org/cactoos/func/FuncWithFallbackTest.java +++ b/src/test/java/org/cactoos/func/FuncWithFallbackTest.java @@ -28,8 +28,8 @@ import java.util.IllegalFormatWidthException; import org.cactoos.iterable.IterableOf; import org.cactoos.scalar.FallbackFrom; -import org.hamcrest.MatcherAssert; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; import org.llorllale.cactoos.matchers.FuncApplies; /** @@ -37,14 +37,15 @@ * * @since 0.2 * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ @SuppressWarnings("unchecked") public final class FuncWithFallbackTest { @Test - public void usesMainFunc() throws Exception { + public void usesMainFunc() { final String expected = "It's success"; - MatcherAssert.assertThat( + new Assertion<>( "Can't use the main function if no exception", new FuncWithFallback<>( input -> expected, @@ -54,13 +55,13 @@ public void usesMainFunc() throws Exception { ) ), new FuncApplies<>(1, expected) - ); + ).affirm(); } @Test - public void usesFallback() throws Exception { + public void usesFallback() { final String expected = "Never mind"; - MatcherAssert.assertThat( + new Assertion<>( "Can't use the callback in case of exception", new FuncWithFallback<>( input -> { @@ -69,13 +70,13 @@ public void usesFallback() throws Exception { new FallbackFrom<>(IOException.class, ex -> expected) ), new FuncApplies<>(1, expected) - ); + ).affirm(); } @Test - public void usesFallbackOfInterruptedException() throws Exception { + public void usesFallbackOfInterruptedException() { final String expected = "Fallback from InterruptedException"; - MatcherAssert.assertThat( + new Assertion<>( "Can't use a fallback from Interrupted in case of exception", new FuncWithFallback<>( input -> { @@ -86,13 +87,13 @@ public void usesFallbackOfInterruptedException() throws Exception { new FallbackFrom<>(InterruptedException.class, exp -> expected) ), new FuncApplies<>(1, expected) - ); + ).affirm(); } @Test - public void usesTheClosestFallback() throws Exception { + public void usesTheClosestFallback() { final String expected = "Fallback from IllegalFormatException"; - MatcherAssert.assertThat( + new Assertion<>( "Can't find the closest fallback", new FuncWithFallback<>( input -> { @@ -110,7 +111,7 @@ public void usesTheClosestFallback() throws Exception { ) ), new FuncApplies<>(1, expected) - ); + ).affirm(); } @Test(expected = Exception.class) diff --git a/src/test/java/org/cactoos/func/IoCheckedBiFuncTest.java b/src/test/java/org/cactoos/func/IoCheckedBiFuncTest.java index 3bb4ca6ec6..e8f53a0782 100644 --- a/src/test/java/org/cactoos/func/IoCheckedBiFuncTest.java +++ b/src/test/java/org/cactoos/func/IoCheckedBiFuncTest.java @@ -24,9 +24,9 @@ package org.cactoos.func; 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 IoCheckedBiFunc}. @@ -38,17 +38,18 @@ public final class IoCheckedBiFuncTest { @Test public void rethrowsIoException() { final IOException exception = new IOException("intended"); - try { - new IoCheckedBiFunc<>( + new Assertion<>( + "Must rethrow IOException", + () -> new IoCheckedBiFunc<>( (fst, scd) -> { throw exception; } - ).apply(1, 2); - } catch (final IOException ex) { - MatcherAssert.assertThat( - ex, Matchers.is(exception) - ); - } + ).apply(1, 2), + new Throws<>( + exception.getMessage(), + exception.getClass() + ) + ).affirm(); } @Test(expected = IOException.class) diff --git a/src/test/java/org/cactoos/func/IoCheckedFuncTest.java b/src/test/java/org/cactoos/func/IoCheckedFuncTest.java index 410048bf8f..62a5066df1 100644 --- a/src/test/java/org/cactoos/func/IoCheckedFuncTest.java +++ b/src/test/java/org/cactoos/func/IoCheckedFuncTest.java @@ -24,10 +24,9 @@ package org.cactoos.func; import java.io.IOException; -import org.cactoos.Func; -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 IoCheckedFunc}. @@ -40,35 +39,48 @@ public final class IoCheckedFuncTest { @Test public void rethrowsIoException() { final IOException exception = new IOException("intended"); - try { - new IoCheckedFunc<>( - (Func) i -> { + new Assertion<>( + "Must rethrow original IOException", + () -> new IoCheckedFunc<>( + i -> { throw exception; } - ).apply(1); - } catch (final IOException ex) { - MatcherAssert.assertThat( - ex, Matchers.is(exception) - ); - } + ).apply(1), + new Throws<>( + exception.getMessage(), + exception.getClass() + ) + ).affirm(); } - @Test(expected = IOException.class) - public void rethrowsCheckedToIoException() throws Exception { - new IoCheckedFunc<>( - i -> { - throw new IOException("intended to fail"); - } - ).apply(1); + @Test + public void rethrowsCheckedToIoException() { + new Assertion<>( + "Must rethrow as IOException", + () -> new IoCheckedFunc<>( + i -> { + throw new InterruptedException("intended to fail"); + } + ).apply(1), + new Throws<>( + IOException.class + ) + ).affirm(); } - @Test(expected = IllegalStateException.class) - public void runtimeExceptionGoesOut() throws IOException { - new IoCheckedFunc<>( - i -> { - throw new IllegalStateException("intended to fail here"); - } - ).apply(1); + @Test + public void runtimeExceptionGoesOut() { + new Assertion<>( + "Must throw runtime exception as is", + () -> new IoCheckedFunc<>( + i -> { + throw new IllegalStateException("intended to fail here"); + } + ).apply(1), + new Throws<>( + IllegalStateException.class + ) + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/IoCheckedProcTest.java b/src/test/java/org/cactoos/func/IoCheckedProcTest.java index 7173c6161a..ee46ba421d 100644 --- a/src/test/java/org/cactoos/func/IoCheckedProcTest.java +++ b/src/test/java/org/cactoos/func/IoCheckedProcTest.java @@ -25,9 +25,9 @@ import java.io.IOException; import org.cactoos.Proc; -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 IoCheckedProc}. @@ -39,35 +39,50 @@ public final class IoCheckedProcTest { @Test public void rethrowsIoException() { final IOException exception = new IOException("intended"); - try { - new IoCheckedProc<>( - (Proc) i -> { - throw exception; - } - ).exec(1); - } catch (final IOException ex) { - MatcherAssert.assertThat( - ex, Matchers.is(exception) - ); - } + new Assertion<>( + "Must rethrow original IOException", + () -> { + new IoCheckedProc<>( + (Proc) i -> { + throw exception; + } + ).exec(1); + return null; + }, + new Throws<>(exception.getMessage(), exception.getClass()) + ).affirm(); } - @Test(expected = IOException.class) - public void rethrowsCheckedToIoException() throws Exception { - new IoCheckedProc<>( - i -> { - throw new InterruptedException("intended to fail"); - } - ).exec(1); + @Test + public void rethrowsCheckedToIoException() { + new Assertion<>( + "Must wrap and throw IOException", + () -> { + new IoCheckedProc<>( + (Proc) i -> { + throw new InterruptedException("intended to fail"); + } + ).exec(1); + return null; + }, + new Throws<>(IOException.class) + ).affirm(); } - @Test(expected = IllegalStateException.class) - public void runtimeExceptionGoesOut() throws IOException { - new IoCheckedProc<>( - i -> { - throw new IllegalStateException("intended to fail here"); - } - ).exec(1); + @Test + public void runtimeExceptionGoesOut() { + new Assertion<>( + "Must throw runtime exceptions as is", + () -> { + new IoCheckedProc<>( + i -> { + throw new IllegalStateException("intended to fail here"); + } + ).exec(1); + return null; + }, + new Throws<>(IllegalStateException.class) + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/ProcOfTest.java b/src/test/java/org/cactoos/func/ProcOfTest.java index ffaaf8b51f..a597af93b2 100644 --- a/src/test/java/org/cactoos/func/ProcOfTest.java +++ b/src/test/java/org/cactoos/func/ProcOfTest.java @@ -27,9 +27,9 @@ import java.util.List; import java.util.concurrent.Callable; import org.cactoos.text.FormattedText; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; /** * Test case for {@link ProcOf}. @@ -51,14 +51,14 @@ public void run() { } } ).exec("You can use any input in a Runnable."); - MatcherAssert.assertThat( + new Assertion<>( new FormattedText( "Wrong result when created with a Runnable. Expected %s", str ).asString(), list, Matchers.contains(str) - ); + ).affirm(); } @Test @@ -74,14 +74,14 @@ public String call() throws Exception { } } ).exec("You can use any input in a Callable"); - MatcherAssert.assertThat( + new Assertion<>( new FormattedText( "Wrong result when created with a Callable. Expected %s", str ).asString(), list, Matchers.contains(str) - ); + ).affirm(); } @Test @@ -94,13 +94,13 @@ public void worksWithFunc() throws Exception { return list.size(); } ).exec(str); - MatcherAssert.assertThat( + new Assertion<>( new FormattedText( "Wrong result when created with a Func. Expected %s", str ).asString(), list, Matchers.contains(str) - ); + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/RepeatedTest.java b/src/test/java/org/cactoos/func/RepeatedTest.java index c3c4f11396..be19d17f89 100644 --- a/src/test/java/org/cactoos/func/RepeatedTest.java +++ b/src/test/java/org/cactoos/func/RepeatedTest.java @@ -27,9 +27,10 @@ import java.util.Iterator; import org.cactoos.Func; import org.cactoos.iterator.IteratorOf; -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 Repeated}. @@ -44,42 +45,41 @@ public final class RepeatedTest { public void runsFuncMultipleTimes() throws Exception { final Iterator iter = new IteratorOf<>(1, 2, 5, 6); final Func func = new Repeated<>( - input -> { - return iter.next(); - }, + input -> iter.next(), 3 ); - MatcherAssert.assertThat( + new Assertion<>( + "Must be applied 3 times", func.apply(true), Matchers.equalTo(5) - ); + ).affirm(); } @Test public void repeatsNullsResults() throws Exception { final Func func = new Repeated<>( - input -> { - return null; - }, + input -> null, 2 ); - MatcherAssert.assertThat( + new Assertion<>( + "Must repeat NULL", func.apply(true), Matchers.equalTo(null) - ); + ).affirm(); } - @Test(expected = IllegalArgumentException.class) - public void doesntRepeatAny() throws Exception { + @Test + public void doesntRepeatAny() { final Func func = new Repeated<>( - input -> { - return new SecureRandom().nextInt(); - }, + input -> new SecureRandom().nextInt(), 0 ); - MatcherAssert.assertThat( - func.apply(true), - Matchers.equalTo(func.apply(true)) - ); + new Assertion<>( + "Must throw if parameter is not correct", + () -> func.apply(true), + new Throws<>( + IllegalArgumentException.class + ) + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/RunnableOfTest.java b/src/test/java/org/cactoos/func/RunnableOfTest.java index d3c1b2b625..55ee91c0d1 100644 --- a/src/test/java/org/cactoos/func/RunnableOfTest.java +++ b/src/test/java/org/cactoos/func/RunnableOfTest.java @@ -24,8 +24,8 @@ package org.cactoos.func; import java.util.concurrent.atomic.AtomicBoolean; -import org.hamcrest.MatcherAssert; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; import org.llorllale.cactoos.matchers.MatcherOf; /** @@ -39,7 +39,7 @@ public final class RunnableOfTest { @Test public void convertsFuncIntoRunnable() { final AtomicBoolean done = new AtomicBoolean(); - MatcherAssert.assertThat( + new Assertion<>( "Can't execute Runnable with Func", new RunnableOf<>( input -> { @@ -53,13 +53,13 @@ public void convertsFuncIntoRunnable() { return done.get(); } ) - ); + ).affirm(); } @Test public void convertsProcIntoRunnable() { final AtomicBoolean done = new AtomicBoolean(); - MatcherAssert.assertThat( + new Assertion<>( "Can't execute Runnable with ProcOf", new RunnableOf<>( new ProcOf<>( @@ -75,13 +75,13 @@ public void convertsProcIntoRunnable() { return done.get(); } ) - ); + ).affirm(); } @Test public void convertsCallableIntoRunnable() { final AtomicBoolean done = new AtomicBoolean(); - MatcherAssert.assertThat( + new Assertion<>( "Can't execute Runnable with Callable", new RunnableOf<>( () -> { @@ -95,7 +95,7 @@ public void convertsCallableIntoRunnable() { return done.get(); } ) - ); + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/SolidBiFuncTest.java b/src/test/java/org/cactoos/func/SolidBiFuncTest.java index 2307cae970..6e0d95ef7b 100644 --- a/src/test/java/org/cactoos/func/SolidBiFuncTest.java +++ b/src/test/java/org/cactoos/func/SolidBiFuncTest.java @@ -26,9 +26,9 @@ import java.security.SecureRandom; import org.cactoos.BiFunc; import org.cactoos.Func; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; import org.llorllale.cactoos.matchers.RunsInThreads; /** @@ -49,19 +49,19 @@ public void testThatFuncIsSynchronized() { return true; } ); - MatcherAssert.assertThat( + new Assertion<>( "SolidBiFunc can't work properly in concurrent threads.", func -> func.apply(true), - new RunsInThreads<>( - (Func) input -> testable.apply(1, 1), + new RunsInThreads>( + input -> testable.apply(1, 1), threads ) - ); - MatcherAssert.assertThat( + ).affirm(); + new Assertion<>( "Shared resource has been modified by multiple threads.", shared[0], Matchers.is(1) - ); + ).affirm(); } @Test @@ -71,10 +71,10 @@ public void testThatFuncResultCacheIsLimited() throws Exception { (first, second) -> new SecureRandom().nextInt(), 1 ); - MatcherAssert.assertThat( + new Assertion<>( "Result of (0, 0) call wasn't invalidated.", func.apply(0, 0) + func.apply(1, 1), Matchers.not(func.apply(1, 1) + func.apply(0, 0)) - ); + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/SolidFuncTest.java b/src/test/java/org/cactoos/func/SolidFuncTest.java index 36b30492b7..6574696b94 100644 --- a/src/test/java/org/cactoos/func/SolidFuncTest.java +++ b/src/test/java/org/cactoos/func/SolidFuncTest.java @@ -26,9 +26,9 @@ import java.security.SecureRandom; import org.cactoos.Func; import org.cactoos.list.ListOf; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; import org.llorllale.cactoos.matchers.RunsInThreads; /** @@ -44,27 +44,29 @@ public void cachesFuncResults() throws Exception { final Func func = new SolidFunc<>( input -> new SecureRandom().nextInt() ); - MatcherAssert.assertThat( + new Assertion<>( + "Must cache results", func.apply(true) + func.apply(true), Matchers.equalTo(func.apply(true) + func.apply(true)) - ); + ).affirm(); } @Test public void worksInThreads() { - MatcherAssert.assertThat( - "Can't work well in multiple threads", + new Assertion<>( + "Must work well in multiple threads", func -> { - MatcherAssert.assertThat( + new Assertion<>( + "Result must be cached", func.apply(true), Matchers.equalTo(func.apply(true)) - ); + ).affirm(); return true; }, new RunsInThreads<>( new SolidFunc<>(x -> new ListOf<>(1, 2)) ) - ); + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/StickyBiFuncTest.java b/src/test/java/org/cactoos/func/StickyBiFuncTest.java index edbcf35b39..f0044d16f4 100644 --- a/src/test/java/org/cactoos/func/StickyBiFuncTest.java +++ b/src/test/java/org/cactoos/func/StickyBiFuncTest.java @@ -25,9 +25,9 @@ import java.security.SecureRandom; import org.cactoos.BiFunc; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; /** * Test case for {@link StickyBiFunc}. @@ -41,10 +41,11 @@ public void cachesFuncResults() throws Exception { final BiFunc func = new StickyBiFunc<>( (first, second) -> new SecureRandom().nextInt() ); - MatcherAssert.assertThat( + new Assertion<>( + "Must cache results", func.apply(true, true) + func.apply(true, true), Matchers.equalTo(func.apply(true, true) + func.apply(true, true)) - ); + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/StickyFuncTest.java b/src/test/java/org/cactoos/func/StickyFuncTest.java index 93597e27d1..5d0e696c02 100644 --- a/src/test/java/org/cactoos/func/StickyFuncTest.java +++ b/src/test/java/org/cactoos/func/StickyFuncTest.java @@ -25,9 +25,9 @@ import java.security.SecureRandom; import org.cactoos.Func; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; /** * Test case for {@link StickyFunc}. @@ -42,10 +42,13 @@ public void cachesFuncResults() throws Exception { final Func func = new StickyFunc<>( input -> new SecureRandom().nextInt() ); - MatcherAssert.assertThat( + new Assertion<>( + "Must cache results", func.apply(true) + func.apply(true), - Matchers.equalTo(func.apply(true) + func.apply(true)) - ); + Matchers.equalTo( + func.apply(true) + func.apply(true) + ) + ).affirm(); } @Test @@ -55,15 +58,17 @@ public void cachesWithLimitedBuffer() throws Exception { ); final int first = func.apply(0); final int second = func.apply(1); - MatcherAssert.assertThat( + new Assertion<>( + "Must cache two results", first + second, Matchers.equalTo(func.apply(0) + func.apply(1)) - ); + ).affirm(); final int third = func.apply(-1); - MatcherAssert.assertThat( + new Assertion<>( + "Must cache next two results", second + third, Matchers.equalTo(func.apply(1) + func.apply(-1)) - ); + ).affirm(); } @Test @@ -71,10 +76,11 @@ public void cachesWithZeroBuffer() throws Exception { final Func func = new StickyFunc<>( input -> new SecureRandom().nextInt(), 0 ); - MatcherAssert.assertThat( + new Assertion<>( + "Must be not be cached", func.apply(true) + func.apply(true), Matchers.not(Matchers.equalTo(func.apply(true) + func.apply(true))) - ); + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/SyncFuncTest.java b/src/test/java/org/cactoos/func/SyncFuncTest.java index c31ff9329a..e1b674ed40 100644 --- a/src/test/java/org/cactoos/func/SyncFuncTest.java +++ b/src/test/java/org/cactoos/func/SyncFuncTest.java @@ -25,9 +25,9 @@ import java.util.LinkedList; import java.util.List; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; import org.llorllale.cactoos.matchers.RunsInThreads; /** @@ -36,32 +36,35 @@ * @since 0.24 * @checkstyle JavadocMethodCheck (500 lines) */ +@SuppressWarnings("PMD.AvoidDuplicateLiterals") public final class SyncFuncTest { @Test public void funcWorksInThreads() { final List list = new LinkedList<>(); final int threads = 100; - MatcherAssert.assertThat( + new Assertion<>( "Sync func can't work well in multiple threads", func -> func.apply(true), new RunsInThreads<>( new SyncFunc( - input -> { - return list.add(1); - } + input -> list.add(1) ), threads ) - ); - MatcherAssert.assertThat(list.size(), Matchers.equalTo(threads)); + ).affirm(); + new Assertion<>( + "Must run the expected amount of threads", + list.size(), + Matchers.equalTo(threads) + ).affirm(); } @Test public void procWorksInThreads() { final int threads = 100; final int[] counter = new int[]{0}; - MatcherAssert.assertThat( + new Assertion<>( "Sync func with proc can't work well in multiple threads", func -> func.apply(1), new RunsInThreads<>( @@ -73,15 +76,19 @@ public void procWorksInThreads() { ), threads ) - ); - MatcherAssert.assertThat(counter[0], Matchers.equalTo(threads)); + ).affirm(); + new Assertion<>( + "Must run the expected amount of threads", + counter[0], + Matchers.equalTo(threads) + ).affirm(); } @Test public void callableWorksInThreads() { final int threads = 100; final int[] counter = new int[]{0}; - MatcherAssert.assertThat( + new Assertion<>( "Sync func with callable can't work well in multiple threads", func -> func.apply(1), new RunsInThreads<>( @@ -93,15 +100,19 @@ public void callableWorksInThreads() { ), threads ) - ); - MatcherAssert.assertThat(counter[0], Matchers.equalTo(threads)); + ).affirm(); + new Assertion<>( + "Must run the expected amount of threads", + counter[0], + Matchers.equalTo(threads) + ).affirm(); } @Test public void runnableWorksInThreads() { final int threads = 100; final int[] counter = new int[]{0}; - MatcherAssert.assertThat( + new Assertion<>( "Sync func with runnable can't work well in multiple threads", func -> func.apply(1), new RunsInThreads<>( @@ -111,7 +122,11 @@ public void runnableWorksInThreads() { ), threads ) - ); - MatcherAssert.assertThat(counter[0], Matchers.equalTo(threads)); + ).affirm(); + new Assertion<>( + "Must run the expected amount of threads", + counter[0], + Matchers.equalTo(threads) + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/TimedFuncTest.java b/src/test/java/org/cactoos/func/TimedFuncTest.java index 454b706355..9c76888a84 100644 --- a/src/test/java/org/cactoos/func/TimedFuncTest.java +++ b/src/test/java/org/cactoos/func/TimedFuncTest.java @@ -28,9 +28,9 @@ import java.util.concurrent.TimeoutException; import org.cactoos.iterable.Endless; import org.cactoos.scalar.And; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; /** * Test case for {@link Timed}. @@ -71,23 +71,25 @@ public void futureTaskIsCancelled() { ).apply(true); // @checkstyle IllegalCatchCheck (1 line) } catch (final Exception exp) { - MatcherAssert.assertThat( + new Assertion<>( + "Must be canceled after 1 sec", future.isCancelled(), Matchers.equalTo(true) - ); + ).affirm(); } } @Test public void functionIsExecuted() throws Exception { final long period = 3000L; - MatcherAssert.assertThat( + new Assertion<>( + "Must execute the function", new Timed( input -> true, period ).apply(true), Matchers.equalTo(true) - ); + ).affirm(); } } diff --git a/src/test/java/org/cactoos/func/UncheckedBiFuncTest.java b/src/test/java/org/cactoos/func/UncheckedBiFuncTest.java index a4027b0884..ba091fa8ae 100644 --- a/src/test/java/org/cactoos/func/UncheckedBiFuncTest.java +++ b/src/test/java/org/cactoos/func/UncheckedBiFuncTest.java @@ -25,9 +25,9 @@ import java.io.IOException; import java.io.UncheckedIOException; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; /** * Test case for {@link UncheckedBiFunc}. @@ -47,12 +47,13 @@ public void rethrowsCheckedToUncheckedException() { @Test public void testUncheckedBiFunc() { - MatcherAssert.assertThat( + new Assertion<>( + "Must return value", new UncheckedBiFunc<>( (fst, scd) -> true ).apply(1, 2), Matchers.equalTo(true) - ); + ).affirm(); } @Test(expected = IllegalStateException.class) diff --git a/src/test/java/org/cactoos/package-info.java b/src/test/java/org/cactoos/package-info.java index baf2f48f21..587364ecfe 100644 --- a/src/test/java/org/cactoos/package-info.java +++ b/src/test/java/org/cactoos/package-info.java @@ -25,6 +25,11 @@ /** * Tests. * + * @todo #1396:30min Continue replacing usage of MatcherAssert.assertThat with + * Assertion from cactoos-matchers. Keep PR short and limit the changes to + * single package. Update this puzzle for the next package. + * After all packages are done, add MatcherAssert to forbidden-apis.txt + * * @since 0.9 */ package org.cactoos; diff --git a/src/test/java/org/cactoos/scalar/package-info.java b/src/test/java/org/cactoos/scalar/package-info.java index 6af123caf3..8af04fdc08 100644 --- a/src/test/java/org/cactoos/scalar/package-info.java +++ b/src/test/java/org/cactoos/scalar/package-info.java @@ -25,10 +25,6 @@ /** * Scalars, tests. * - * @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;