use of com.birbit.android.jobqueue.test.timer.MockTimer in project android-priority-jobqueue by yigit.
the class RunningJobSetTest method testAddWithTimeout.
@Test
public void testAddWithTimeout() {
MockTimer timer = new MockTimer();
set = new RunningJobSet(timer);
set.addGroupUntil("g1", 10L);
timer.setNow(5);
assertList("g1");
timer.setNow(11);
assertList();
timer.setNow(3);
// should've pruned the list
assertList();
}
use of com.birbit.android.jobqueue.test.timer.MockTimer in project android-priority-jobqueue by yigit.
the class RunningJobSetTest method testAddMultipleGroupTimeouts.
@Test
public void testAddMultipleGroupTimeouts() {
MockTimer timer = new MockTimer();
set = new RunningJobSet(timer);
set.addGroupUntil("g1", 10L);
set.addGroupUntil("g2", 20L);
timer.setNow(5);
assertList("g1", "g2");
timer.setNow(11);
assertList("g2");
timer.setNow(21);
assertList();
}
use of com.birbit.android.jobqueue.test.timer.MockTimer 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.test.timer.MockTimer 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.test.timer.MockTimer in project android-priority-jobqueue by yigit.
the class JobParamsTest method assertParamsUnderstood.
@Test
public void assertParamsUnderstood() {
MockTimer mockTimer = new MockTimer();
JobHolder j1 = JobQueueTestBase.createNewJobHolder(new Params(1).requireNetwork(), mockTimer);
assertThat("require network param should be understood properly", j1.getRequiredNetworkType(), equalTo(NetworkUtil.METERED));
JobHolder j2 = JobQueueTestBase.createNewJobHolder(new Params(1).groupBy("blah"), mockTimer);
assertThat("group param should be understood properly", j2.getGroupId(), equalTo("blah"));
assertThat("require network param should be understood properly", j2.getRequiredNetworkType(), equalTo(NetworkUtil.DISCONNECTED));
JobHolder j3 = JobQueueTestBase.createNewJobHolder(new Params(1).persist(), mockTimer);
assertThat("persist param should be understood properly", j3.persistent, equalTo(true));
JobHolder j4 = JobQueueTestBase.createNewJobHolder(new Params(1).setPersistent(false).setRequiresNetwork(false).setGroupId(null).setSingleId(null), mockTimer);
assertThat("persist param should be understood properly", j4.persistent, equalTo(false));
assertThat("require network param should be understood properly", j4.getRequiredNetworkType(), equalTo(NetworkUtil.DISCONNECTED));
assertThat("group param should be understood properly", j4.groupId, nullValue());
assertThat("single param should be understood properly", j4.getSingleInstanceId(), nullValue());
mockTimer.incrementMs(2);
DummyJob j15 = new DummyJob(new Params(1).singleInstanceBy("bloop"));
assertThat("single param should be understood properly", j15.getSingleInstanceId(), endsWith("bloop"));
assertThat("group param should be automatically set if single instance", j15.getRunGroupId(), notNullValue());
mockTimer.setNow(150);
JobHolder j6 = JobQueueTestBase.createNewJobHolder(new Params(1), mockTimer);
assertThat("no deadline", j6.getDeadlineNs(), is(Params.FOREVER));
JobHolder j7 = JobQueueTestBase.createNewJobHolder(new Params(1).overrideDeadlineToCancelInMs(100), mockTimer);
assertThat("100 ms deadline", j7.getDeadlineNs(), is(100000150L));
assertThat("100 ms deadline", j7.shouldCancelOnDeadline(), is(true));
JobHolder j13 = JobQueueTestBase.createNewJobHolder(new Params(1).overrideDeadlineToCancelInMs(200), mockTimer);
assertThat("100 ms deadline", j13.getDeadlineNs(), is(200000150L));
assertThat("100 ms deadline", j7.shouldCancelOnDeadline(), is(true));
}
Aggregations