An implementation of the Wait interface that may have its timeout and polling interval configured on the fly. Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configu
| 67 | * @param <T> The input type for each condition used with this instance. |
| 68 | */ |
| 69 | public class FluentWait<T> implements Wait<T> { |
| 70 | |
| 71 | protected static final long DEFAULT_SLEEP_TIMEOUT = 500; |
| 72 | |
| 73 | private static final Duration DEFAULT_WAIT_DURATION = Duration.ofMillis(DEFAULT_SLEEP_TIMEOUT); |
| 74 | |
| 75 | protected final T input; |
| 76 | protected final java.time.Clock clock; |
| 77 | protected final Sleeper sleeper; |
| 78 | |
| 79 | protected Duration timeout = DEFAULT_WAIT_DURATION; |
| 80 | protected Duration interval = DEFAULT_WAIT_DURATION; |
| 81 | protected Supplier<@Nullable String> messageSupplier = () -> null; |
| 82 | |
| 83 | protected final List<Class<? extends Throwable>> ignoredExceptions = new ArrayList<>(); |
| 84 | |
| 85 | /** |
| 86 | * @param input The input value to pass to the evaluated conditions. |
| 87 | */ |
| 88 | public FluentWait(T input) { |
| 89 | this(input, Clock.systemDefaultZone(), Sleeper.SYSTEM_SLEEPER); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @param input The input value to pass to the evaluated conditions. |
| 94 | * @param clock The clock to use when measuring the timeout. |
| 95 | * @param sleeper Used to put the thread to sleep between evaluation loops. |
| 96 | */ |
| 97 | public FluentWait(T input, java.time.Clock clock, Sleeper sleeper) { |
| 98 | this.input = input; |
| 99 | this.clock = Require.nonNull("Clock", clock); |
| 100 | this.sleeper = Require.nonNull("Sleeper", sleeper); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Sets how long to wait for the evaluated condition to be true. The default timeout is {@link |
| 105 | * #DEFAULT_WAIT_DURATION}. |
| 106 | * |
| 107 | * @param timeout The timeout duration. |
| 108 | * @return A self reference. |
| 109 | */ |
| 110 | public FluentWait<T> withTimeout(Duration timeout) { |
| 111 | this.timeout = timeout; |
| 112 | return this; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Sets the message to be displayed when time expires. |
| 117 | * |
| 118 | * @param message to be appended to default. |
| 119 | * @return A self reference. |
| 120 | */ |
| 121 | public FluentWait<T> withMessage(final String message) { |
| 122 | Require.nonNull("Message", message); |
| 123 | this.messageSupplier = () -> message; |
| 124 | return this; |
| 125 | } |
| 126 |
nothing calls this directly
no outgoing calls
no test coverage detected