-
Notifications
You must be signed in to change notification settings - Fork 395
Espresso Idling Resource Example
Yigit Boyar edited this page Oct 11, 2016
·
3 revisions
final IdlingResource.ResourceCallback[] resourceCallbacks = new IdlingResource.ResourceCallback[1];
jobManager.addCallback(new JobManagerCallbackAdapter() {
@Override
public void onJobAdded(@NonNull Job job) {
jobCount.incrementAndGet();
}
@Override
public void onDone(@NonNull Job job) {
if (jobCount.decrementAndGet() == 0 && resourceCallbacks[0] != null) {
resourceCallbacks[0].onTransitionToIdle();
}
}
});
Espresso.registerIdlingResources(new IdlingResource() {
@Override
public String getName() {
return "job-manager";
}
@Override
public boolean isIdleNow() {
return jobCount.get() == 0;
}
@Override
public void registerIdleTransitionCallback(ResourceCallback callback) {
resourceCallbacks[0] = callback;
}
});