public void waitUntilFinished() {
    while ( !isFinished() && !job.isStopped() ) {
      try {
        Thread.sleep( 0, 1 );
      } catch ( InterruptedException e ) {
        // Ignore errors
      }
    }
  }
@Test
  public void testWaitUntilFinished() throws Exception {
    when( mockJob.isStopped() ).thenReturn( true );
    when( mockJob.getParentJob() ).thenReturn( parentJob );
    when( parentJob.isStopped() ).thenReturn( false );
    when( mockJob.execute( Mockito.anyInt(), Mockito.any( Result.class ) ) ).thenReturn( mockResult );
    jobRunner.waitUntilFinished();
  }