diff --git a/src/main/java/org/cactoos/func/Async.java b/src/main/java/org/cactoos/func/Async.java index 0dcda999c0..c30251a81d 100644 --- a/src/main/java/org/cactoos/func/Async.java +++ b/src/main/java/org/cactoos/func/Async.java @@ -45,11 +45,6 @@ * @param Type of input * @param Type of output * @since 0.10 - * @todo #861:30min Avoid usage of null value in ctor(Proc, ExecutorService), - * ctor(Proc, ThreadFactory) and ctor(Proc) which is against design - * principles. - * Perhaps with a creation of AsyncProc or removal of this functionality? - * Please take a look on #551 and #843 for more details. */ public final class Async implements Func>, Proc { @@ -63,14 +58,6 @@ public final class Async implements Func>, Proc { */ private final ExecutorService executor; - /** - * Ctor. - * @param proc The proc - */ - public Async(final Proc proc) { - this(new FuncOf<>(proc, null)); - } - /** * Ctor. * @param fnc The func @@ -79,15 +66,6 @@ public Async(final Func fnc) { this(fnc, Executors.defaultThreadFactory()); } - /** - * Ctor. - * @param proc The proc - * @param fct Factory - */ - public Async(final Proc proc, final ThreadFactory fct) { - this(new FuncOf<>(proc, null), fct); - } - /** * Ctor. * @param fnc The func @@ -97,16 +75,6 @@ public Async(final Func fnc, final ThreadFactory fct) { this(fnc, Executors.newSingleThreadExecutor(fct)); } - /** - * Ctor. - * @param proc The proc - * @param exec Executor Service - * @since 0.17 - */ - public Async(final Proc proc, final ExecutorService exec) { - this(new FuncOf<>(proc, null), exec); - } - /** * Ctor. * @param fnc The func diff --git a/src/test/java/org/cactoos/func/AsyncTest.java b/src/test/java/org/cactoos/func/AsyncTest.java index f8b6c90a1e..2fc4b8c737 100644 --- a/src/test/java/org/cactoos/func/AsyncTest.java +++ b/src/test/java/org/cactoos/func/AsyncTest.java @@ -27,10 +27,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; -import org.cactoos.Proc; -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.FuncApplies; import org.llorllale.cactoos.matchers.MatcherOf; @@ -39,13 +38,14 @@ * * @since 0.10 * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ public final class AsyncTest { @Test public void runsInBackground() { - MatcherAssert.assertThat( + new Assertion<>( "Can't run in the background", - new Async<>( + () -> new Async<>( input -> { TimeUnit.DAYS.sleep(1L); return "done!"; @@ -57,36 +57,34 @@ public void runsInBackground() { future -> !future.isDone() ) ) - ); + ).affirm(); } @Test public void runsAsProcInBackground() { - MatcherAssert.assertThat( + new Assertion<>( "Can't run proc in the background", - input -> { + () -> input -> { final CountDownLatch latch = new CountDownLatch(1); new Async<>( - (Proc) ipt -> latch.countDown() + new FuncOf<>(ipt -> latch.countDown(), true) ).exec(input); latch.await(); return true; }, new FuncApplies<>( - true, Matchers.equalTo(true) + true, new IsEqual<>(true) ) - ); + ).affirm(); } @Test public void runsInBackgroundWithoutFuture() { final CountDownLatch latch = new CountDownLatch(1); - MatcherAssert.assertThat( + new Assertion<>( "Can't run in the background without us touching the Future", - new Async<>( - input -> { - latch.countDown(); - } + () -> new Async<>( + new FuncOf<>(input -> latch.countDown(), true) ), new FuncApplies<>( true, @@ -96,7 +94,7 @@ public void runsInBackgroundWithoutFuture() { } ) ) - ); + ).affirm(); } @Test @@ -104,17 +102,20 @@ public void runsInBackgroundWithThreadFactory() { final String name = "secret name for thread factory"; final ThreadFactory factory = r -> new Thread(r, name); final CountDownLatch latch = new CountDownLatch(1); - MatcherAssert.assertThat( + new Assertion<>( "Can't run in the background with specific thread factory", - new Async<>( - input -> { - if (!input.equals(Thread.currentThread().getName())) { - throw new IllegalStateException( - "Another thread factory was used" - ); - } - latch.countDown(); - }, + () -> new Async<>( + new FuncOf<>( + input -> { + if (!input.equals(Thread.currentThread().getName())) { + throw new IllegalStateException( + "Another thread factory was used" + ); + } + latch.countDown(); + }, + true + ), factory ), new FuncApplies<>( @@ -126,7 +127,7 @@ public void runsInBackgroundWithThreadFactory() { } ) ) - ); + ).affirm(); } @Test @@ -134,17 +135,20 @@ public void runsInBackgroundWithExecutorService() { final String name = "secret name for thread executor"; final ThreadFactory factory = r -> new Thread(r, name); final CountDownLatch latch = new CountDownLatch(1); - MatcherAssert.assertThat( + new Assertion<>( "Can't run in the background with specific thread executor", - new Async<>( - input -> { - if (!input.equals(Thread.currentThread().getName())) { - throw new IllegalStateException( - "Another thread executor was used" - ); - } - latch.countDown(); - }, + () -> new Async<>( + new FuncOf<>( + input -> { + if (!input.equals(Thread.currentThread().getName())) { + throw new IllegalStateException( + "Another thread executor was used" + ); + } + latch.countDown(); + }, + true + ), Executors.newSingleThreadExecutor(factory) ), new FuncApplies<>( @@ -156,6 +160,6 @@ public void runsInBackgroundWithExecutorService() { } ) ) - ); + ).affirm(); } }