Skip to content

Commit d83e403

Browse files
committed
refactor: Deprecate custom functional interfaces
1 parent 735e9fb commit d83e403

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
import java.util.function.Supplier;
2222

23+
/**
24+
* Represents a supplier of actions.
25+
*
26+
* @deprecated Use {@link Supplier} instead
27+
*/
28+
@Deprecated
2329
@FunctionalInterface
2430
public interface ActionSupplier<T extends PerformsActions<?>> extends Supplier<T> {
2531
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
*
2929
* @param <F> The input type
3030
* @param <T> The return type
31+
* @deprecated Use {@link java.util.function.Function} instead
3132
*/
33+
@Deprecated
3234
@FunctionalInterface
3335
public interface AppiumFunction<F, T> extends Function<F, T>, java.util.function.Function<F, T> {
3436

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
* with {@link java.util.function.Function}.
2424
*
2525
* @param <T> The return type
26+
* @deprecated Use {@link org.openqa.selenium.support.ui.ExpectedCondition} instead
2627
*/
28+
@Deprecated
2729
@FunctionalInterface
2830
public interface ExpectedCondition<T> extends org.openqa.selenium.support.ui.ExpectedCondition<T>,
2931
AppiumFunction<WebDriver, T> {

src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.appium.java_client.android;
22

33
import io.appium.java_client.AppiumBy;
4-
import io.appium.java_client.functions.ActionSupplier;
54
import io.appium.java_client.touch.offset.ElementOption;
65
import org.junit.jupiter.api.Test;
76
import org.openqa.selenium.By;
@@ -10,6 +9,7 @@
109

1110
import java.util.List;
1211
import java.util.Map;
12+
import java.util.function.Supplier;
1313

1414
import static io.appium.java_client.TestUtils.getCenter;
1515
import static io.appium.java_client.touch.WaitOptions.waitOptions;
@@ -19,7 +19,7 @@
1919

2020
public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
2121

22-
private final ActionSupplier<AndroidTouchAction> horizontalSwipe = () -> {
22+
private final Supplier<AndroidTouchAction> horizontalSwipe = () -> {
2323
driver.findElement(By.id("io.appium.android.apis:id/gallery"));
2424

2525
WebElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery"));
@@ -37,7 +37,7 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
3737
.release();
3838
};
3939

40-
private final ActionSupplier<AndroidTouchAction> verticalSwiping = () ->
40+
private final Supplier<AndroidTouchAction> verticalSwiping = () ->
4141
new AndroidTouchAction(driver)
4242
.press(element(driver.findElement(AppiumBy.accessibilityId("Gallery"))))
4343

src/test/java/io/appium/java_client/android/AndroidFunctionTest.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package io.appium.java_client.android;
22

3-
import io.appium.java_client.functions.AppiumFunction;
4-
import io.appium.java_client.functions.ExpectedCondition;
53
import org.junit.jupiter.api.BeforeAll;
64
import org.junit.jupiter.api.BeforeEach;
75
import org.junit.jupiter.api.Test;
86
import org.openqa.selenium.By;
97
import org.openqa.selenium.TimeoutException;
108
import org.openqa.selenium.WebDriver;
119
import org.openqa.selenium.WebElement;
10+
import org.openqa.selenium.support.ui.ExpectedCondition;
1211
import org.openqa.selenium.support.ui.FluentWait;
1312
import org.openqa.selenium.support.ui.Wait;
1413

1514
import java.util.ArrayList;
1615
import java.util.List;
1716
import java.util.Set;
17+
import java.util.function.Function;
1818
import java.util.regex.Matcher;
1919
import java.util.regex.Pattern;
2020

@@ -27,16 +27,13 @@
2727

2828
public class AndroidFunctionTest extends BaseAndroidTest {
2929

30-
private final AppiumFunction<WebDriver, List<WebElement>> searchingFunction = input -> {
30+
private final Function<WebDriver, List<WebElement>> searchingFunction = input -> {
3131
List<WebElement> result = input.findElements(By.tagName("a"));
3232

33-
if (result.size() > 0) {
34-
return result;
35-
}
36-
return null;
33+
return result.isEmpty() ? null : result;
3734
};
3835

39-
private final AppiumFunction<Pattern, WebDriver> contextFunction = input -> {
36+
private final Function<Pattern, WebDriver> contextFunction = input -> {
4037
Set<String> contexts = driver.getContextHandles();
4138
String current = driver.getContext();
4239
contexts.forEach(context -> {
@@ -51,18 +48,15 @@ public class AndroidFunctionTest extends BaseAndroidTest {
5148
return null;
5249
};
5350

54-
private final AppiumFunction<List<WebElement>, List<WebElement>> filteringFunction = input -> {
51+
private final Function<List<WebElement>, List<WebElement>> filteringFunction = input -> {
5552
final List<WebElement> result = new ArrayList<>();
5653
input.forEach(element -> {
5754
if (element.getText().equals("Hello World! - 1")) {
5855
result.add(element);
5956
}
6057
});
6158

62-
if (result.size() > 0) {
63-
return result;
64-
}
65-
return null;
59+
return result.isEmpty() ? null : result;
6660
};
6761

6862
@BeforeAll
@@ -80,8 +74,7 @@ public void setUp() {
8074

8175
@Test
8276
public void complexWaitingTestWithPreCondition() {
83-
AppiumFunction<Pattern, List<WebElement>> compositeFunction =
84-
searchingFunction.compose(contextFunction);
77+
Function<Pattern, List<WebElement>> compositeFunction = searchingFunction.compose(contextFunction);
8578

8679
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW"))
8780
.withTimeout(ofSeconds(30));
@@ -94,23 +87,23 @@ public void complexWaitingTestWithPreCondition() {
9487
@Test public void complexWaitingTestWithPostConditions() {
9588
final List<Boolean> calls = new ArrayList<>();
9689

97-
AppiumFunction<Pattern, WebDriver> waitingForContext = input -> {
90+
Function<Pattern, WebDriver> waitingForContext = input -> {
9891
WebDriver result = contextFunction.apply(input);
9992
if (result != null) {
10093
calls.add(true);
10194
}
10295
return result;
10396
};
10497

105-
AppiumFunction<Pattern, List<WebElement>> compositeFunction = waitingForContext
98+
Function<Pattern, List<WebElement>> compositeFunction = waitingForContext
10699
.andThen((ExpectedCondition<List<WebElement>>) input -> {
107100
List<WebElement> result = searchingFunction.apply(input);
108101
if (result != null) {
109102
calls.add(true);
110103
}
111104
return result;
112105
})
113-
.andThen((AppiumFunction<List<WebElement>, List<WebElement>>) input -> {
106+
.andThen(input -> {
114107
List<WebElement> result = filteringFunction.apply(input);
115108
if (result != null) {
116109
calls.add(true);

0 commit comments

Comments
 (0)