Skip to content

Instantly share code, notes, and snippets.

@rpgobjects
Last active April 6, 2018 03:54
Show Gist options
  • Select an option

  • Save rpgobjects/ed023abb8e00d000fa3e to your computer and use it in GitHub Desktop.

Select an option

Save rpgobjects/ed023abb8e00d000fa3e to your computer and use it in GitHub Desktop.
Espresso IdlingResource for Ion
/**
* Espresso IdlingResource for Ion
* https://github.com/koush/ion
* https://code.google.com/p/android-test-kit/
* Because you can't deregister an IdlingResource, you have to create a new one per test.
* You need to use a unique resourceName each test.
*/
public final class IonIdlingResource implements IdlingResource {
private static final String TAG = "IonIdlingResource";
private final String resourceName;
private Context context;
private volatile ResourceCallback resourceCallback;
public IonIdlingResource(String resourceName, Context context) {
this.resourceName = resourceName;
this.context = context;
}
@Override
public String getName() {
return resourceName;
}
@Override
public boolean isIdleNow() {
int count = Ion.getDefault(context).getPendingRequestCount(context);
if(count == 0) {
resourceCallback.onTransitionToIdle();
}
Log.d(TAG,resourceName + " count=" + count);
return count == 0;
}
@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment