@Test public void testPerfectExecution() throws Exception { final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>()); final AsyncTask<Object> task = mock(AsyncTask.class); final Object result = new Object(); when(task.call()).thenReturn(result); service.execute(task); verify(task, timeout(2000)).onPostCall(eq(result)); final InOrder inOrder = inOrder(task); inOrder.verify(task, times(1)).onPreCall(); inOrder.verify(task, times(1)).call(); inOrder.verify(task, times(1)).onPostCall(eq(result)); verifyNoMoreInteractions(task); }
public <T> void execute(final AsyncTask<T> task) { try { task.onPreCall(); } catch (Exception e) { task.onError(e); return; } service.submit(new FutureTask<T>(task) { @Override protected void done() { super.done(); try { task.onPostCall(get()); } catch (InterruptedException e) { } catch (ExecutionException e) { task.onError(e.getCause()); } } }); }
AsynchronousService { public <T> void execute(final AsyncTask<T> task) { try { task.onPreCall(); } catch (Exception e) { task.onError(e); return; } service.submit(new FutureTask<T>(task) { @Override protected void done() { super.done(); try { task.onPostCall(get()); } catch (InterruptedException e) { } catch (ExecutionException e) { task.onError(e.getCause()); } } }); } }
AsynchronousService { public <T> void execute(final AsyncTask<T> task) { try { task.onPreCall(); } catch (Exception e) { task.onError(e); return; } service.submit(new FutureTask<T>(task) { @Override protected void done() { super.done(); try { task.onPostCall(get()); } catch (InterruptedException e) { } catch (ExecutionException e) { task.onError(e.getCause()); } } }); } AsynchronousService(BlockingQueue<Runnable> workQueue); }
AsynchronousService { public <T> void execute(final AsyncTask<T> task) { try { task.onPreCall(); } catch (Exception e) { task.onError(e); return; } service.submit(new FutureTask<T>(task) { @Override protected void done() { super.done(); try { task.onPostCall(get()); } catch (InterruptedException e) { } catch (ExecutionException e) { task.onError(e.getCause()); } } }); } AsynchronousService(BlockingQueue<Runnable> workQueue); void execute(final AsyncTask<T> task); }
AsynchronousService { public <T> void execute(final AsyncTask<T> task) { try { task.onPreCall(); } catch (Exception e) { task.onError(e); return; } service.submit(new FutureTask<T>(task) { @Override protected void done() { super.done(); try { task.onPostCall(get()); } catch (InterruptedException e) { } catch (ExecutionException e) { task.onError(e.getCause()); } } }); } AsynchronousService(BlockingQueue<Runnable> workQueue); void execute(final AsyncTask<T> task);  }