File tree Expand file tree Collapse file tree 2 files changed +6
-28
lines changed
src/org/openqa/selenium/support/ui
test/org/openqa/selenium/support/ui Expand file tree Collapse file tree 2 files changed +6
-28
lines changed Original file line number Diff line number Diff line change 17
17
18
18
package org .openqa .selenium .support .ui ;
19
19
20
+ import java .time .temporal .ChronoUnit ;
20
21
import java .util .concurrent .TimeUnit ;
21
22
22
23
/**
23
24
* Abstraction around {@link Thread#sleep(long)} to permit better testability.
24
25
*/
25
26
public interface Sleeper {
26
27
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 ());
47
29
48
30
/**
49
31
* Sleeps for the specified duration of time.
@@ -54,7 +36,9 @@ public void sleep(java.time.Duration duration) throws InterruptedException {
54
36
* @throws InterruptedException If the thread is interrupted while sleeping.
55
37
*/
56
38
@ 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
+ }
58
42
59
43
/**
60
44
* Sleeps for the specified duration of time.
Original file line number Diff line number Diff line change 17
17
18
18
package org .openqa .selenium .support .ui ;
19
19
20
- import java .util .concurrent .TimeUnit ;
21
-
22
20
public class TickingClock implements Clock , Sleeper {
23
21
private long now = 0 ;
24
22
@@ -34,12 +32,8 @@ public boolean isNowBefore(long endInMillis) {
34
32
return now < endInMillis ;
35
33
}
36
34
37
- public void sleep (Duration duration ) {
38
- now += duration .in (TimeUnit .MILLISECONDS );
39
- }
40
-
41
35
@ Override
42
- public void sleep (java .time .Duration duration ) throws InterruptedException {
36
+ public void sleep (java .time .Duration duration ) {
43
37
now += duration .toMillis ();
44
38
}
45
39
}
You can’t perform that action at this time.
0 commit comments