Skip to content

Commit

Permalink
Less use of deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Mar 4, 2018
1 parent 8450067 commit ff621a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
26 changes: 5 additions & 21 deletions java/client/src/org/openqa/selenium/support/ui/Sleeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,15 @@

package org.openqa.selenium.support.ui;

import java.time.temporal.ChronoUnit;
import java.util.concurrent.TimeUnit;

/**
* Abstraction around {@link Thread#sleep(long)} to permit better testability.
*/
public interface Sleeper {

public static final Sleeper SYSTEM_SLEEPER = new Sleeper() {

/**
* Sleeps for the specified duration of time.
*
* @deprecated use {@link #sleep(java.time.Duration)}
*
* @param duration How long to sleep.
* @throws InterruptedException If the thread is interrupted while sleeping.
*/
@Deprecated
public void sleep(Duration duration) throws InterruptedException {
Thread.sleep(duration.in(TimeUnit.MILLISECONDS));
}

@Override
public void sleep(java.time.Duration duration) throws InterruptedException {
Thread.sleep(duration.toMillis());
}
};
Sleeper SYSTEM_SLEEPER = duration -> Thread.sleep(duration.toMillis());

/**
* Sleeps for the specified duration of time.
Expand All @@ -54,7 +36,9 @@ public void sleep(java.time.Duration duration) throws InterruptedException {
* @throws InterruptedException If the thread is interrupted while sleeping.
*/
@Deprecated
void sleep(Duration duration) throws InterruptedException;
default void sleep(Duration duration) throws InterruptedException {
sleep(java.time.Duration.of(duration.in(TimeUnit.MILLISECONDS), ChronoUnit.MICROS));

This comment has been minimized.

Copy link
@dr29bart

dr29bart Mar 4, 2018

Millis as micros? Is it ok?
Shouldn't be
java.time.Duration.ofMillis?

This comment has been minimized.

Copy link
@barancev

barancev Mar 4, 2018

Author Member

Thank you! Fixed in 8d0c109

}

/**
* Sleeps for the specified duration of time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.openqa.selenium.support.ui;

import java.util.concurrent.TimeUnit;

public class TickingClock implements Clock, Sleeper {
private long now = 0;

Expand All @@ -34,12 +32,8 @@ public boolean isNowBefore(long endInMillis) {
return now < endInMillis;
}

public void sleep(Duration duration) {
now += duration.in(TimeUnit.MILLISECONDS);
}

@Override
public void sleep(java.time.Duration duration) throws InterruptedException {
public void sleep(java.time.Duration duration) {
now += duration.toMillis();
}
}

0 comments on commit ff621a2

Please sign in to comment.