Skip to content

Instantly share code, notes, and snippets.

@elcioabrahao
Created April 2, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elcioabrahao/18b8d3515f6ec12e1cee3b4a3b2a6bfd to your computer and use it in GitHub Desktop.
Save elcioabrahao/18b8d3515f6ec12e1cee3b4a3b2a6bfd to your computer and use it in GitHub Desktop.
package br.com.trainning.pdv_2016;
import android.support.test.espresso.IdlingResource;
/**
* Created by elcio on 27/03/16.
*/
public class ElapsedTimeIdlingResource implements IdlingResource {
private final long startTime;
private final long waitingTime;
private ResourceCallback resourceCallback;
public ElapsedTimeIdlingResource(long waitingTime) {
this.startTime = System.currentTimeMillis();
this.waitingTime = waitingTime;
}
@Override
public String getName() {
return ElapsedTimeIdlingResource.class.getName() + ":" + waitingTime;
}
@Override
public boolean isIdleNow() {
long elapsed = System.currentTimeMillis() - startTime;
boolean idle = (elapsed >= waitingTime);
if (idle) {
resourceCallback.onTransitionToIdle();
}
return idle;
}
@Override
public void registerIdleTransitionCallback(
IdlingResource.ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment