Last active
April 6, 2018 03:54
-
-
Save rpgobjects/ed023abb8e00d000fa3e to your computer and use it in GitHub Desktop.
Espresso IdlingResource for Ion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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