Apply code formatting rules to async-method-invocation example tests

This commit is contained in:
Ilkka Seppala 2015-12-06 21:42:06 +02:00
parent 601964a2d1
commit 6c1f025d0f

View File

@ -55,7 +55,8 @@ public class ThreadAsyncExecutorTest {
} }
/** /**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} * Test used to verify the happy path of
* {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)}
*/ */
@Test(timeout = 3000) @Test(timeout = 3000)
public void testSuccessfulTaskWithCallback() throws Exception { public void testSuccessfulTaskWithCallback() throws Exception {
@ -76,7 +77,8 @@ public class ThreadAsyncExecutorTest {
verify(task, times(1)).call(); verify(task, times(1)).call();
// ... same for the callback, we expect our object // ... same for the callback, we expect our object
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class); final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor
.forClass((Class) Optional.class);
verify(callback, times(1)).onComplete(eq(result), optionalCaptor.capture()); verify(callback, times(1)).onComplete(eq(result), optionalCaptor.capture());
final Optional<Exception> optionalException = optionalCaptor.getValue(); final Optional<Exception> optionalException = optionalCaptor.getValue();
@ -88,8 +90,8 @@ public class ThreadAsyncExecutorTest {
} }
/** /**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)} * Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)} when a
* when a task takes a while to execute * task takes a while to execute
*/ */
@Test(timeout = 5000) @Test(timeout = 5000)
public void testLongRunningTaskWithoutCallback() throws Exception { public void testLongRunningTaskWithoutCallback() throws Exception {
@ -109,7 +111,8 @@ public class ThreadAsyncExecutorTest {
try { try {
asyncResult.getValue(); asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task"); fail(
"Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
} }
@ -127,8 +130,9 @@ public class ThreadAsyncExecutorTest {
} }
/** /**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} * Test used to verify the happy path of
* when a task takes a while to execute * {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when a task takes a while to
* execute
*/ */
@Test(timeout = 5000) @Test(timeout = 5000)
public void testLongRunningTaskWithCallback() throws Exception { public void testLongRunningTaskWithCallback() throws Exception {
@ -151,7 +155,8 @@ public class ThreadAsyncExecutorTest {
try { try {
asyncResult.getValue(); asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task"); fail(
"Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
} }
@ -159,7 +164,8 @@ public class ThreadAsyncExecutorTest {
// Our task should only execute once, but it can take a while ... // Our task should only execute once, but it can take a while ...
verify(task, timeout(3000).times(1)).call(); verify(task, timeout(3000).times(1)).call();
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class); final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor
.forClass((Class) Optional.class);
verify(callback, timeout(3000).times(1)).onComplete(eq(result), optionalCaptor.capture()); verify(callback, timeout(3000).times(1)).onComplete(eq(result), optionalCaptor.capture());
final Optional<Exception> optionalException = optionalCaptor.getValue(); final Optional<Exception> optionalException = optionalCaptor.getValue();
@ -176,8 +182,9 @@ public class ThreadAsyncExecutorTest {
} }
/** /**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)} * Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)} when a
* when a task takes a while to execute, while waiting on the result using {@link ThreadAsyncExecutor#endProcess(AsyncResult)} * task takes a while to execute, while waiting on the result using
* {@link ThreadAsyncExecutor#endProcess(AsyncResult)}
*/ */
@Test(timeout = 5000) @Test(timeout = 5000)
public void testEndProcess() throws Exception { public void testEndProcess() throws Exception {
@ -197,7 +204,8 @@ public class ThreadAsyncExecutorTest {
try { try {
asyncResult.getValue(); asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task"); fail(
"Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
} }
@ -212,8 +220,8 @@ public class ThreadAsyncExecutorTest {
} }
/** /**
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable)} * Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable)} when
* when the callable is 'null' * the callable is 'null'
*/ */
@Test(timeout = 3000) @Test(timeout = 3000)
public void testNullTask() throws Exception { public void testNullTask() throws Exception {
@ -221,7 +229,8 @@ public class ThreadAsyncExecutorTest {
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor(); final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final AsyncResult<Object> asyncResult = executor.startProcess(null); final AsyncResult<Object> asyncResult = executor.startProcess(null);
assertNotNull("The AsyncResult should not be 'null', even though the task was 'null'.", asyncResult); assertNotNull("The AsyncResult should not be 'null', even though the task was 'null'.",
asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted()); assertTrue(asyncResult.isCompleted());
@ -237,8 +246,9 @@ public class ThreadAsyncExecutorTest {
} }
/** /**
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} * Test used to verify the behaviour of
* when the callable is 'null', but the asynchronous callback is provided * {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when the callable is 'null',
* but the asynchronous callback is provided
*/ */
@Test(timeout = 3000) @Test(timeout = 3000)
public void testNullTaskWithCallback() throws Exception { public void testNullTaskWithCallback() throws Exception {
@ -247,11 +257,13 @@ public class ThreadAsyncExecutorTest {
final AsyncCallback<Object> callback = mock(AsyncCallback.class); final AsyncCallback<Object> callback = mock(AsyncCallback.class);
final AsyncResult<Object> asyncResult = executor.startProcess(null, callback); final AsyncResult<Object> asyncResult = executor.startProcess(null, callback);
assertNotNull("The AsyncResult should not be 'null', even though the task was 'null'.", asyncResult); assertNotNull("The AsyncResult should not be 'null', even though the task was 'null'.",
asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted()); assertTrue(asyncResult.isCompleted());
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class); final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor
.forClass((Class) Optional.class);
verify(callback, times(1)).onComplete(Matchers.isNull(), optionalCaptor.capture()); verify(callback, times(1)).onComplete(Matchers.isNull(), optionalCaptor.capture());
final Optional<Exception> optionalException = optionalCaptor.getValue(); final Optional<Exception> optionalException = optionalCaptor.getValue();
@ -274,8 +286,9 @@ public class ThreadAsyncExecutorTest {
} }
/** /**
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} * Test used to verify the behaviour of
* when both the callable and the asynchronous callback are 'null' * {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when both the callable and
* the asynchronous callback are 'null'
*/ */
@Test(timeout = 3000) @Test(timeout = 3000)
public void testNullTaskWithNullCallback() throws Exception { public void testNullTaskWithNullCallback() throws Exception {
@ -283,7 +296,9 @@ public class ThreadAsyncExecutorTest {
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor(); final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final AsyncResult<Object> asyncResult = executor.startProcess(null, null); final AsyncResult<Object> asyncResult = executor.startProcess(null, null);
assertNotNull("The AsyncResult should not be 'null', even though the task and callback were 'null'.", asyncResult); assertNotNull(
"The AsyncResult should not be 'null', even though the task and callback were 'null'.",
asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted()); assertTrue(asyncResult.isCompleted());