Skip to content

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;
            }
        });
Clone this wiki locally