### Question:
TrivialTask extends AbstractSimpleTask { @Override public Void call() throws Exception { setState(ExecutionState.RUNNING); try { callable.call(); incrementProgress(); } catch (Exception e) { setState(ExecutionState.FAILED); throw e; } setState(ExecutionState.COMPLETED); return null; } TrivialTask(String name, Runnable r);  TrivialTask(String name, Callable<?> callable); @Override Void call();  }### Answer:
@Test(groups = { TestGroups.UNIT }) public void runnableTest() throws Exception { final Runnable mock = createMockRunnable(); final Task t = new TrivialTask("Foo", mock); t.call(); EasyMock.verify(mock); }
@Test(groups = { TestGroups.UNIT }) public void runnableProgressTest() throws Exception { final Runnable mock = createMockRunnable(); final ProgressListener listener = createMockListener(PENDING_REPORT, RUNNING_REPORT, INCREMENTED_REPORT, COMPLETED_REPORT); final Task t = new TrivialTask("Foo", mock); t.addListener(listener); t.requestProgressReport(); t.call(); EasyMock.verify(mock); EasyMock.verify(listener); }
@Test(groups = { TestGroups.UNIT }) public void callableTest() throws Exception { final Callable<?> mock = createMockCallable(); final Task t = new TrivialTask("Foo", mock); t.call(); EasyMock.verify(mock); }
@Test(groups = { TestGroups.UNIT }) public void callableProgressTest() throws Exception { final Callable<?> mock = createMockCallable(); final ProgressListener listener = createMockListener(PENDING_REPORT, RUNNING_REPORT, INCREMENTED_REPORT, COMPLETED_REPORT); final Task t = new TrivialTask("Foo", mock); t.addListener(listener); t.requestProgressReport(); t.call(); EasyMock.verify(mock); EasyMock.verify(listener); }
@Test(groups = { TestGroups.UNIT }, expectedExceptions = {RuntimeException.class}) public void callableErrorTest() throws Exception { final Task t = new TrivialTask("Foo", new Callable<Void>() { @Override public Void call() throws Exception { throw new RuntimeException(); } }); t.call(); }
@Test(groups = { TestGroups.UNIT }) public void callableErrorProgressTest() throws Exception { final Task t = new TrivialTask("Foo", new Callable<Void>() { @Override public Void call() throws Exception { throw new RuntimeException(); } }); final ProgressListener listener = createMockListener(PENDING_REPORT, RUNNING_REPORT, FAILED_REPORT); t.addListener(listener); t.requestProgressReport(); try { t.call(); } catch (RuntimeException e) { } EasyMock.verify(listener); }