|
19 | 19 | import com.google.common.base.Throwables; |
20 | 20 | import lombok.AccessLevel; |
21 | 21 | import lombok.Getter; |
| 22 | +import org.jspecify.annotations.NonNull; |
| 23 | +import org.jspecify.annotations.NullMarked; |
| 24 | +import org.jspecify.annotations.Nullable; |
22 | 25 | import org.openqa.selenium.TimeoutException; |
23 | 26 | import org.openqa.selenium.WebDriverException; |
24 | 27 | import org.openqa.selenium.support.ui.FluentWait; |
|
32 | 35 | import java.util.function.Function; |
33 | 36 | import java.util.function.Supplier; |
34 | 37 |
|
| 38 | +@NullMarked |
35 | 39 | public class AppiumFluentWait<T> extends FluentWait<T> { |
| 40 | + @Nullable |
36 | 41 | private Function<IterationInfo, Duration> pollingStrategy = null; |
37 | 42 |
|
38 | 43 | private static final Duration DEFAULT_POLL_DELAY_DURATION = Duration.ZERO; |
@@ -133,7 +138,7 @@ protected List<Class<? extends Throwable>> getIgnoredExceptions() { |
133 | 138 | return ignoredExceptions; |
134 | 139 | } |
135 | 140 |
|
136 | | - protected Supplier<String> getMessageSupplier() { |
| 141 | + protected Supplier<@Nullable String> getMessageSupplier() { |
137 | 142 | return messageSupplier; |
138 | 143 | } |
139 | 144 |
|
@@ -203,15 +208,15 @@ public AppiumFluentWait<T> withPollingStrategy(Function<IterationInfo, Duration> |
203 | 208 | * @throws TimeoutException If the timeout expires. |
204 | 209 | */ |
205 | 210 | @Override |
206 | | - public <V> V until(Function<? super T, V> isTrue) { |
| 211 | + public <V extends @Nullable Object> @NonNull V until(Function<? super T, ? extends V> isTrue) { |
207 | 212 | final var start = getClock().instant(); |
208 | 213 | // Adding pollDelay to end instant will allow to verify the condition for the expected timeout duration. |
209 | 214 | final var end = start.plus(getTimeout()).plus(pollDelay); |
210 | 215 |
|
211 | 216 | return performIteration(isTrue, start, end); |
212 | 217 | } |
213 | 218 |
|
214 | | - private <V> V performIteration(Function<? super T, V> isTrue, Instant start, Instant end) { |
| 219 | + private <V extends @Nullable Object> @NonNull V performIteration(Function<? super T, ? extends V> isTrue, Instant start, Instant end) { |
215 | 220 | var iterationNumber = 1; |
216 | 221 | Throwable lastException; |
217 | 222 |
|
@@ -245,8 +250,8 @@ private <V> V performIteration(Function<? super T, V> isTrue, Instant start, Ins |
245 | 250 | } |
246 | 251 | } |
247 | 252 |
|
248 | | - private <V> void handleTimeoutException(Throwable lastException, Function<? super T, V> isTrue) { |
249 | | - var message = Optional.ofNullable(getMessageSupplier()) |
| 253 | + private <V> void handleTimeoutException(@Nullable Throwable lastException, Function<? super T, ? extends V> isTrue) { |
| 254 | + var message = Optional.of(getMessageSupplier()) |
250 | 255 | .map(Supplier::get) |
251 | 256 | .orElseGet(() -> "waiting for " + isTrue); |
252 | 257 |
|
|
0 commit comments