use of com.birbit.android.jobqueue.scheduling.Scheduler in project android-priority-jobqueue by yigit.
the class BatchingSchedulerTest method testCustomDuration.
@Test
public void testCustomDuration() {
scheduler = mock(Scheduler.class);
timer = new MockTimer();
bs = new BatchingScheduler(scheduler, timer, 123);
MatcherAssert.assertThat(bs.batchingDurationInMs, CoreMatchers.is(123L));
MatcherAssert.assertThat(bs.batchingDurationInNs, CoreMatchers.is(123000000L));
}
use of com.birbit.android.jobqueue.scheduling.Scheduler in project android-priority-jobqueue by yigit.
the class BatchingSchedulerTest method init.
@Before
public void init() {
scheduler = mock(Scheduler.class);
timer = new MockTimer();
bs = new BatchingScheduler(scheduler, timer);
Context context = mock(Context.class);
when(context.getApplicationContext()).thenReturn(mock(Context.class));
bs.init(context, mock(Scheduler.Callback.class));
}
use of com.birbit.android.jobqueue.scheduling.Scheduler in project android-priority-jobqueue by yigit.
the class SchedulerSimpleTestCase method testScheduleWhenJobAdded.
@Test
public void testScheduleWhenJobAdded() throws InterruptedException {
Scheduler scheduler = Mockito.mock(Scheduler.class);
ArgumentCaptor<SchedulerConstraint> captor = ArgumentCaptor.forClass(SchedulerConstraint.class);
DummyNetworkUtilWithConnectivityEventSupport networkUtil = new DummyNetworkUtilWithConnectivityEventSupport();
Configuration.Builder builder = new Configuration.Builder(RuntimeEnvironment.application).timer(mockTimer).networkUtil(networkUtil).inTestMode().scheduler(scheduler, false);
if (requireUnmeteredNetwork) {
networkUtil.setNetworkStatus(NetworkUtil.UNMETERED);
} else if (requireNetwork) {
networkUtil.setNetworkStatus(NetworkUtil.METERED);
} else {
networkUtil.setNetworkStatus(NetworkUtil.DISCONNECTED);
}
final JobManager jobManager = createJobManager(builder);
Params params = new Params(1);
params.setPersistent(persistent);
params.setRequiresNetwork(requireNetwork);
params.setRequiresUnmeteredNetwork(requireUnmeteredNetwork);
params.setDelayMs(delayInMs);
if (deadline != null) {
params.overrideDeadlineToRunInMs(deadline);
}
final SchedulerJob job = new SchedulerJob(params);
final CountDownLatch cancelLatch = new CountDownLatch(1);
Mockito.doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
cancelLatch.countDown();
return null;
}
}).when(scheduler).cancelAll();
waitUntilJobsAreDone(jobManager, Collections.singletonList(job), new Runnable() {
@Override
public void run() {
jobManager.addJob(job);
mockTimer.incrementMs(delayInMs);
}
});
if (persistent && (requireNetwork || requireUnmeteredNetwork || delayInMs >= JobManager.MIN_DELAY_TO_USE_SCHEDULER_IN_MS || (deadline != null && deadline >= JobManager.MIN_DELAY_TO_USE_SCHEDULER_IN_MS))) {
Mockito.verify(scheduler).request(captor.capture());
SchedulerConstraint constraint = captor.getValue();
MatcherAssert.assertThat(constraint.getNetworkStatus(), CoreMatchers.is(requireUnmeteredNetwork ? NetworkUtil.UNMETERED : requireNetwork ? NetworkUtil.METERED : NetworkUtil.DISCONNECTED));
MatcherAssert.assertThat(constraint.getDelayInMs(), CoreMatchers.is(delayInMs));
// wait until cancel is called because it is called when JQ is idle.
// for more clear reporting, let mockito handle the check
MatcherAssert.assertThat(constraint.getOverrideDeadlineInMs(), CoreMatchers.is(deadline));
cancelLatch.await(30, TimeUnit.SECONDS);
Mockito.verify(scheduler).cancelAll();
} else {
Mockito.verify(scheduler, Mockito.never()).request(Mockito.any(SchedulerConstraint.class));
}
}
Aggregations