Created
April 2, 2016 17:13
-
-
Save elcioabrahao/18b8d3515f6ec12e1cee3b4a3b2a6bfd to your computer and use it in GitHub Desktop.
This file contains 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
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