use of com.birbit.android.jobqueue.di.DependencyInjector in project android-priority-jobqueue by yigit.
the class InjectorTest method testInjector.
@Test
public void testInjector() throws Throwable {
Configuration.Builder builder = new Configuration.Builder(RuntimeEnvironment.application);
final JobManagerTestBase.ObjectReference injectedJobReference = new JobManagerTestBase.ObjectReference();
final AtomicInteger injectionCallCount = new AtomicInteger(0);
DependencyInjector dependencyInjector = new DependencyInjector() {
@Override
public void inject(Job job) {
injectedJobReference.setObject(job);
injectionCallCount.incrementAndGet();
}
};
builder.injector(dependencyInjector);
builder.timer(mockTimer);
JobManager jobManager = createJobManager(builder);
jobManager.stop();
jobManager.addJob(new DummyJob(new Params(4)));
MatcherAssert.assertThat("injection should be called after adding a non-persistent job", injectionCallCount.get(), equalTo(1));
jobManager.addJob(new DummyJob(new Params(1).persist()));
MatcherAssert.assertThat("injection should be called after adding a persistent job", injectionCallCount.get(), equalTo(2));
JobHolder holder = nextJob(jobManager);
MatcherAssert.assertThat("injection should NOT be called for non persistent job", holder.getJob(), not(injectedJobReference.getObject()));
MatcherAssert.assertThat("injection should be called once for non persistent job", injectionCallCount.get(), equalTo(2));
holder = nextJob(jobManager);
MatcherAssert.assertThat("injection should be called for persistent job", holder.getJob(), equalTo(injectedJobReference.getObject()));
MatcherAssert.assertThat("injection should be called two times for persistent job", injectionCallCount.get(), equalTo(3));
}
Aggregations