Code example for AsyncTask

Methods: execute, sleep

0
        try { 
            a.startSync();
        } catch (InterruptedException e1) {
            fail("interrupted");
        } 
        assertFalse("not start", AsyncTaskUtils.isRunning(a.getTask()));
 
        // start and wait for the task start running 
        a.getTask().execute();
 
        try { 
            a.waitForStart();
        } catch (InterruptedException e) {
            fail("interrupted");
        } 
        assertTrue("the task has been started", a.isStarted());
        assertTrue("running", AsyncTaskUtils.isRunning(a.getTask()));
         
        a.checkPoint();
         
        // wait for the task ends 
        try { 
            a.waitForEnd();
        } catch (InterruptedException e) {
            fail("interrupted");
        } 
        assertTrue("the task was finished", a.isEnded());
         
        // probably some time required to change the state 
        try { 
            Thread.sleep(500);
        } catch (InterruptedException e) {
            fail("interrupted");
        } 
         
        assertFalse("finished", AsyncTaskUtils.isRunning(a.getTask()));
    } 
}