Skip to content

Commit ff621a2

Browse files
committed
Less use of deprecated API
1 parent 8450067 commit ff621a2

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

java/client/src/org/openqa/selenium/support/ui/Sleeper.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,15 @@
1717

1818
package org.openqa.selenium.support.ui;
1919

20+
import java.time.temporal.ChronoUnit;
2021
import java.util.concurrent.TimeUnit;
2122

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

27-
public static final Sleeper SYSTEM_SLEEPER = new Sleeper() {
28-
29-
/**
30-
* Sleeps for the specified duration of time.
31-
*
32-
* @deprecated use {@link #sleep(java.time.Duration)}
33-
*
34-
* @param duration How long to sleep.
35-
* @throws InterruptedException If the thread is interrupted while sleeping.
36-
*/
37-
@Deprecated
38-
public void sleep(Duration duration) throws InterruptedException {
39-
Thread.sleep(duration.in(TimeUnit.MILLISECONDS));
40-
}
41-
42-
@Override
43-
public void sleep(java.time.Duration duration) throws InterruptedException {
44-
Thread.sleep(duration.toMillis());
45-
}
46-
};
28+
Sleeper SYSTEM_SLEEPER = duration -> Thread.sleep(duration.toMillis());
4729

4830
/**
4931
* Sleeps for the specified duration of time.
@@ -54,7 +36,9 @@ public void sleep(java.time.Duration duration) throws InterruptedException {
5436
* @throws InterruptedException If the thread is interrupted while sleeping.
5537
*/
5638
@Deprecated
57-
void sleep(Duration duration) throws InterruptedException;
39+
default void sleep(Duration duration) throws InterruptedException {
40+
sleep(java.time.Duration.of(duration.in(TimeUnit.MILLISECONDS), ChronoUnit.MICROS));
41+
}
5842

5943
/**
6044
* Sleeps for the specified duration of time.

java/client/test/org/openqa/selenium/support/ui/TickingClock.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.openqa.selenium.support.ui;
1919

20-
import java.util.concurrent.TimeUnit;
21-
2220
public class TickingClock implements Clock, Sleeper {
2321
private long now = 0;
2422

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

37-
public void sleep(Duration duration) {
38-
now += duration.in(TimeUnit.MILLISECONDS);
39-
}
40-
4135
@Override
42-
public void sleep(java.time.Duration duration) throws InterruptedException {
36+
public void sleep(java.time.Duration duration) {
4337
now += duration.toMillis();
4438
}
4539
}

0 commit comments

Comments
 (0)