Skip to content

Instantly share code, notes, and snippets.

@mykola-dev
Created April 15, 2016 15:47
Show Gist options
  • Save mykola-dev/bbfe0c8799003c170fcf3b70feb6c35f to your computer and use it in GitHub Desktop.
Save mykola-dev/bbfe0c8799003c170fcf3b70feb6c35f to your computer and use it in GitHub Desktop.
public class ElapsedTimeIdlingResource implements IdlingResource {
private static ElapsedTimeIdlingResource DEFAULT_RESOURCE;
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(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment