Skip to content

Commit f2b547d

Browse files
ExpectedCondition enhancement
Methods `compose` and `andThen` were overridden the way to prevent NPE occurence.
1 parent 5dba790 commit f2b547d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/main/java/io/appium/java_client/functions/ExpectedCondition.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
import org.openqa.selenium.WebDriver;
2020

21+
import java.util.Objects;
22+
import java.util.Optional;
23+
import java.util.function.Function;
24+
2125
/**
2226
* This is extended version of {@link org.openqa.selenium.support.ui.ExpectedCondition}. It is combined
2327
* with {@link java.util.function.Function}.
@@ -27,4 +31,20 @@
2731
@FunctionalInterface
2832
public interface ExpectedCondition<T> extends org.openqa.selenium.support.ui.ExpectedCondition<T>,
2933
java.util.function.Function<WebDriver, T> {
34+
35+
@Override default <V> Function<V, T> compose(Function<? super V, ? extends WebDriver> before) {
36+
Objects.requireNonNull(before);
37+
return (V v) -> {
38+
WebDriver driver = before.apply(v);
39+
return Optional.ofNullable(driver != null ? apply(driver) : null).orElse(null);
40+
};
41+
}
42+
43+
@Override default <V> Function<WebDriver, V> andThen(Function<? super T, ? extends V> after) {
44+
Objects.requireNonNull(after);
45+
return (WebDriver w) -> {
46+
T result = apply(w);
47+
return Optional.ofNullable(result != null ? after.apply(result) : null).orElse(null);
48+
};
49+
}
3050
}

0 commit comments

Comments
 (0)