Apply code formatting rules to async-method-invocation example tests
This commit is contained in:
parent
601964a2d1
commit
6c1f025d0f
@ -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)
|
||||
public void testSuccessfulTaskWithCallback() throws Exception {
|
||||
@ -76,7 +77,8 @@ public class ThreadAsyncExecutorTest {
|
||||
verify(task, times(1)).call();
|
||||
|
||||
// ... 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());
|
||||
|
||||
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)}
|
||||
* when a task takes a while to execute
|
||||
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)} when a
|
||||
* task takes a while to execute
|
||||
*/
|
||||
@Test(timeout = 5000)
|
||||
public void testLongRunningTaskWithoutCallback() throws Exception {
|
||||
@ -109,7 +111,8 @@ public class ThreadAsyncExecutorTest {
|
||||
|
||||
try {
|
||||
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) {
|
||||
assertNotNull(e.getMessage());
|
||||
}
|
||||
@ -127,8 +130,9 @@ public class ThreadAsyncExecutorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)}
|
||||
* when a task takes a while to execute
|
||||
* Test used to verify the happy path of
|
||||
* {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when a task takes a while to
|
||||
* execute
|
||||
*/
|
||||
@Test(timeout = 5000)
|
||||
public void testLongRunningTaskWithCallback() throws Exception {
|
||||
@ -151,7 +155,8 @@ public class ThreadAsyncExecutorTest {
|
||||
|
||||
try {
|
||||
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) {
|
||||
assertNotNull(e.getMessage());
|
||||
}
|
||||
@ -159,7 +164,8 @@ public class ThreadAsyncExecutorTest {
|
||||
// Our task should only execute once, but it can take a while ...
|
||||
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());
|
||||
|
||||
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)}
|
||||
* when a task takes a while to execute, while waiting on the result using {@link ThreadAsyncExecutor#endProcess(AsyncResult)}
|
||||
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)} when a
|
||||
* task takes a while to execute, while waiting on the result using
|
||||
* {@link ThreadAsyncExecutor#endProcess(AsyncResult)}
|
||||
*/
|
||||
@Test(timeout = 5000)
|
||||
public void testEndProcess() throws Exception {
|
||||
@ -197,7 +204,8 @@ public class ThreadAsyncExecutorTest {
|
||||
|
||||
try {
|
||||
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) {
|
||||
assertNotNull(e.getMessage());
|
||||
}
|
||||
@ -212,8 +220,8 @@ public class ThreadAsyncExecutorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable)}
|
||||
* when the callable is 'null'
|
||||
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable)} when
|
||||
* the callable is 'null'
|
||||
*/
|
||||
@Test(timeout = 3000)
|
||||
public void testNullTask() throws Exception {
|
||||
@ -221,7 +229,8 @@ public class ThreadAsyncExecutorTest {
|
||||
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
|
||||
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
|
||||
assertTrue(asyncResult.isCompleted());
|
||||
|
||||
@ -237,8 +246,9 @@ public class ThreadAsyncExecutorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)}
|
||||
* when the callable is 'null', but the asynchronous callback is provided
|
||||
* Test used to verify the behaviour of
|
||||
* {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when the callable is 'null',
|
||||
* but the asynchronous callback is provided
|
||||
*/
|
||||
@Test(timeout = 3000)
|
||||
public void testNullTaskWithCallback() throws Exception {
|
||||
@ -247,11 +257,13 @@ public class ThreadAsyncExecutorTest {
|
||||
final AsyncCallback<Object> callback = mock(AsyncCallback.class);
|
||||
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
|
||||
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());
|
||||
|
||||
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)}
|
||||
* when both the callable and the asynchronous callback are 'null'
|
||||
* Test used to verify the behaviour of
|
||||
* {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when both the callable and
|
||||
* the asynchronous callback are 'null'
|
||||
*/
|
||||
@Test(timeout = 3000)
|
||||
public void testNullTaskWithNullCallback() throws Exception {
|
||||
@ -283,7 +296,9 @@ public class ThreadAsyncExecutorTest {
|
||||
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
|
||||
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
|
||||
assertTrue(asyncResult.isCompleted());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user