// Path: library/src/test/java/com/doist/jobschedulercompat/util/NoopAsyncJobService.java
// public class NoopAsyncJobService extends JobService {
//     public static final String EXTRA_DELAY = "delay";
// 
//     private static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(0);
//     private static final SparseArray<ScheduledFuture> futures = new SparseArray<>();
// 
//     @Override
//     public boolean onStartJob(final JobParameters params) {
//         final int jobId = params.getJobId();
//         final ScheduledFuture future = executor.schedule(new Runnable() {
//             @Override
//             public void run() {
//                 jobFinished(params, false);
//                 synchronized (futures) {
//                     futures.remove(jobId);
//                 }
//             }
//         }, Math.max(params.getExtras().getLong(EXTRA_DELAY), 1), TimeUnit.MILLISECONDS);
//         synchronized (futures) {
//             futures.append(jobId, future);
//         }
//         return true;
//     }
// 
//     @Override
//     public boolean onStopJob(JobParameters params) {
//         int jobId = params.getJobId();
//         ScheduledFuture future;
//         synchronized (futures) {
//             future = futures.get(jobId);
//             futures.remove(jobId);
//         }
//         if (future != null) {
//             future.cancel(true);
//         }
//         return false;
//     }
// 
//     static void waitForJob(int jobId) {
//         ScheduledFuture future;
//         synchronized (futures) {
//             future = futures.get(jobId);
//         }
//         try {
//             if (future != null) {
//                 future.get();
//             }
//         } catch (InterruptedException | ExecutionException e) {
//             // Ignore.
//         }
//     }
// 
//     static void interruptJobs() {
//         SparseArray<ScheduledFuture> currentFutures;
//         synchronized (futures) {
//             currentFutures = futures.clone();
//             futures.clear();
//         }
//         for (int i = 0; i < currentFutures.size(); i++) {
//             currentFutures.valueAt(i).cancel(true);
//         }
//     }
// }
// 
// Path: library/src/test/java/com/doist/jobschedulercompat/util/NoopJobService.java
// public class NoopJobService extends JobService {
//     @Override
//     public boolean onStartJob(JobParameters params) {
//         return false;
//     }
// 
//     @Override
//     public boolean onStopJob(JobParameters params) {
//         return false;
//     }
// }


import com.doist.jobschedulercompat.util.NoopAsyncJobService;
import com.doist.jobschedulercompat.util.NoopJobService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import android.os.Bundle;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
package com.doist.jobschedulercompat;






@RunWith(RobolectricTestRunner.class)
public class JobServiceTest {
    private static final int TIMEOUT_MS = 200;
    private static final int PARALLEL_COUNT = 1000;

    private JobParameters params = new JobParameters(0, PersistableBundle.EMPTY, Bundle.EMPTY, null, null, null, false);

    @Test
    public void testFinishesSynchronously() {
        JobService.Binder binder =
                (JobService.Binder) Robolectric.buildService(NoopJobService.class).create().get().onBind(null);

        assertFalse(binder.startJob(params, null));
    }

    @Test
    public void testFinishesAsynchronously() throws InterruptedException {
        JobService.Binder binder =
// Path: library/src/test/java/com/doist/jobschedulercompat/util/NoopAsyncJobService.java
// public class NoopAsyncJobService extends JobService {
//     public static final String EXTRA_DELAY = "delay";
// 
//     private static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(0);
//     private static final SparseArray<ScheduledFuture> futures = new SparseArray<>();
// 
//     @Override
//     public boolean onStartJob(final JobParameters params) {
//         final int jobId = params.getJobId();
//         final ScheduledFuture future = executor.schedule(new Runnable() {
//             @Override
//             public void run() {
//                 jobFinished(params, false);
//                 synchronized (futures) {
//                     futures.remove(jobId);
//                 }
//             }
//         }, Math.max(params.getExtras().getLong(EXTRA_DELAY), 1), TimeUnit.MILLISECONDS);
//         synchronized (futures) {
//             futures.append(jobId, future);
//         }
//         return true;
//     }
// 
//     @Override
//     public boolean onStopJob(JobParameters params) {
//         int jobId = params.getJobId();
//         ScheduledFuture future;
//         synchronized (futures) {
//             future = futures.get(jobId);
//             futures.remove(jobId);
//         }
//         if (future != null) {
//             future.cancel(true);
//         }
//         return false;
//     }
// 
//     static void waitForJob(int jobId) {
//         ScheduledFuture future;
//         synchronized (futures) {
//             future = futures.get(jobId);
//         }
//         try {
//             if (future != null) {
//                 future.get();
//             }
//         } catch (InterruptedException | ExecutionException e) {
//             // Ignore.
//         }
//     }
// 
//     static void interruptJobs() {
//         SparseArray<ScheduledFuture> currentFutures;
//         synchronized (futures) {
//             currentFutures = futures.clone();
//             futures.clear();
//         }
//         for (int i = 0; i < currentFutures.size(); i++) {
//             currentFutures.valueAt(i).cancel(true);
//         }
//     }
// }
// 
// Path: library/src/test/java/com/doist/jobschedulercompat/util/NoopJobService.java
// public class NoopJobService extends JobService {
//     @Override
//     public boolean onStartJob(JobParameters params) {
//         return false;
//     }
// 
//     @Override
//     public boolean onStopJob(JobParameters params) {
//         return false;
//     }
// }


// Path: library/src/test/java/com/doist/jobschedulercompat/JobServiceTest.java
import com.doist.jobschedulercompat.util.NoopAsyncJobService;
import com.doist.jobschedulercompat.util.NoopJobService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import android.os.Bundle;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

package com.doist.jobschedulercompat;






@RunWith(RobolectricTestRunner.class)
public class JobServiceTest {
    private static final int TIMEOUT_MS = 200;
    private static final int PARALLEL_COUNT = 1000;

    private JobParameters params = new JobParameters(0, PersistableBundle.EMPTY, Bundle.EMPTY, null, null, null, false);

    @Test
    public void testFinishesSynchronously() {
        JobService.Binder binder =
                (JobService.Binder) Robolectric.buildService(NoopJobService.class).create().get().onBind(null);

        assertFalse(binder.startJob(params, null));
    }

    @Test
    public void testFinishesAsynchronously() throws InterruptedException {
        JobService.Binder binder =
                (JobService.Binder) Robolectric.buildService(NoopAsyncJobService.class).create().get().onBind(null);