Skip to content

Commit

Permalink
refactor: Deprecate custom functional interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed Oct 24, 2023
1 parent 735e9fb commit d83e403
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

import java.util.function.Supplier;

/**
* Represents a supplier of actions.
*
* @deprecated Use {@link Supplier} instead
*/
@Deprecated
@FunctionalInterface
public interface ActionSupplier<T extends PerformsActions<?>> extends Supplier<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
*
* @param <F> The input type
* @param <T> The return type
* @deprecated Use {@link java.util.function.Function} instead
*/
@Deprecated
@FunctionalInterface
public interface AppiumFunction<F, T> extends Function<F, T>, java.util.function.Function<F, T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* with {@link java.util.function.Function}.
*
* @param <T> The return type
* @deprecated Use {@link org.openqa.selenium.support.ui.ExpectedCondition} instead
*/
@Deprecated
@FunctionalInterface
public interface ExpectedCondition<T> extends org.openqa.selenium.support.ui.ExpectedCondition<T>,
AppiumFunction<WebDriver, T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.appium.java_client.android;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.functions.ActionSupplier;
import io.appium.java_client.touch.offset.ElementOption;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
Expand All @@ -10,6 +9,7 @@

import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

import static io.appium.java_client.TestUtils.getCenter;
import static io.appium.java_client.touch.WaitOptions.waitOptions;
Expand All @@ -19,7 +19,7 @@

public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package io.appium.java_client.android;

import io.appium.java_client.functions.AppiumFunction;
import io.appium.java_client.functions.ExpectedCondition;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -27,16 +27,13 @@

public class AndroidFunctionTest extends BaseAndroidTest {

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

if (result.size() > 0) {
return result;
}
return null;
return result.isEmpty() ? null : result;
};

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

private final AppiumFunction<List<WebElement>, List<WebElement>> filteringFunction = input -> {
private final Function<List<WebElement>, List<WebElement>> filteringFunction = input -> {
final List<WebElement> result = new ArrayList<>();
input.forEach(element -> {
if (element.getText().equals("Hello World! - 1")) {
result.add(element);
}
});

if (result.size() > 0) {
return result;
}
return null;
return result.isEmpty() ? null : result;
};

@BeforeAll
Expand All @@ -80,8 +74,7 @@ public void setUp() {

@Test
public void complexWaitingTestWithPreCondition() {
AppiumFunction<Pattern, List<WebElement>> compositeFunction =
searchingFunction.compose(contextFunction);
Function<Pattern, List<WebElement>> compositeFunction = searchingFunction.compose(contextFunction);

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

AppiumFunction<Pattern, WebDriver> waitingForContext = input -> {
Function<Pattern, WebDriver> waitingForContext = input -> {
WebDriver result = contextFunction.apply(input);
if (result != null) {
calls.add(true);
}
return result;
};

AppiumFunction<Pattern, List<WebElement>> compositeFunction = waitingForContext
Function<Pattern, List<WebElement>> compositeFunction = waitingForContext
.andThen((ExpectedCondition<List<WebElement>>) input -> {
List<WebElement> result = searchingFunction.apply(input);
if (result != null) {
calls.add(true);
}
return result;
})
.andThen((AppiumFunction<List<WebElement>, List<WebElement>>) input -> {
.andThen(input -> {
List<WebElement> result = filteringFunction.apply(input);
if (result != null) {
calls.add(true);
Expand Down

0 comments on commit d83e403

Please sign in to comment.