Fixed CS. This closes #1154
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ab0aeca6 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ab0aeca6 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ab0aeca6 Branch: refs/heads/master Commit: ab0aeca6432cb41d8c7086e31a4cd3cba1288d46 Parents: 41634f2 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Sep 5 09:35:44 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Sep 5 09:35:44 2016 +0200 ---------------------------------------------------------------------- .../apache/camel/component/bean/MethodInfo.java | 2 +- .../component/bean/BeanInvokeAsyncTest.java | 25 +++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ab0aeca6/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java b/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java index d4a0c57..532046b 100644 --- a/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java +++ b/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java @@ -307,7 +307,7 @@ public class MethodInfo { .whenComplete((resultObject, e) -> { if (e != null) { exchange.setException(e); - } else if (resultObject != null){ + } else if (resultObject != null) { fillResult(exchange, resultObject); } callback.done(false); http://git-wip-us.apache.org/repos/asf/camel/blob/ab0aeca6/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeAsyncTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeAsyncTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeAsyncTest.java index a8ecf48..1ce151c 100644 --- a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeAsyncTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeAsyncTest.java @@ -16,18 +16,22 @@ */ package org.apache.camel.component.bean; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; +import java.util.function.Function; + import org.apache.camel.CamelExecutionException; import org.apache.camel.ContextTestSupport; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.junit.Assert; -import java.util.concurrent.*; -import java.util.function.Consumer; -import java.util.function.Function; - /** - * @version + * Unit test for Java 8 {@link CompletableFuture} as return type on a bean being called from a Camel route. */ public class BeanInvokeAsyncTest extends ContextTestSupport { @@ -67,20 +71,21 @@ public class BeanInvokeAsyncTest extends ContextTestSupport { } } - private void runTestSendBody(String expectedBody, String sentBody, Function<String, String> processor) - throws InterruptedException, java.util.concurrent.ExecutionException { + private void runTestSendBody(String expectedBody, String sentBody, + Function<String, String> processor) throws Exception { runTestSendBody(m -> m.expectedBodiesReceived(expectedBody), sentBody, processor); } private void runTestSendBody(Consumer<MockEndpoint> mockPreparer, String sentBody, - Function<String, String> processor) - throws InterruptedException, java.util.concurrent.ExecutionException { + Function<String, String> processor) throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.reset(); mockPreparer.accept(mock); + callFuture = new CompletableFuture<>(); methodInvoked = new CountDownLatch(1); sendFuture = template.asyncSendBody("direct:entry", sentBody); + Assert.assertTrue(methodInvoked.await(5, TimeUnit.SECONDS)); Assert.assertEquals(0, mock.getReceivedCounter()); Assert.assertFalse(sendFuture.isDone()); @@ -90,6 +95,7 @@ public class BeanInvokeAsyncTest extends ContextTestSupport { callFuture.completeExceptionally(e); } sendFuture.get(); + assertMockEndpointsSatisfied(); } @@ -108,6 +114,7 @@ public class BeanInvokeAsyncTest extends ContextTestSupport { }; } + // java 8 async return type public CompletableFuture<?> asyncMethod(String body) { this.receivedBody = body; methodInvoked.countDown();