Skip to content

Commit a9240e3

Browse files
authored
refactor: Use Java 9+ APIs instead of outdated/3rd-party APIs (#2048)
1 parent 10a3f62 commit a9240e3

File tree

80 files changed

+387
-432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+387
-432
lines changed

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package io.appium.java_client;
1818

19-
import com.google.common.collect.ImmutableMap;
2019
import io.appium.java_client.internal.CapabilityHelpers;
2120
import io.appium.java_client.internal.ReflectionHelpers;
2221
import io.appium.java_client.internal.SessionHelpers;
@@ -153,7 +152,7 @@ public AppiumDriver(URL remoteSessionAddress, String platformName, String automa
153152
super();
154153
ReflectionHelpers.setPrivateFieldValue(
155154
RemoteWebDriver.class, this, "capabilities", new ImmutableCapabilities(
156-
ImmutableMap.of(
155+
Map.of(
157156
PLATFORM_NAME, platformName,
158157
APPIUM_PREFIX + AUTOMATION_NAME_OPTION, automationName
159158
)

src/main/java/io/appium/java_client/AppiumExecutionMethod.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package io.appium.java_client;
1818

19-
import com.google.common.collect.ImmutableMap;
2019
import org.openqa.selenium.remote.ExecuteMethod;
2120
import org.openqa.selenium.remote.Response;
2221

@@ -40,7 +39,7 @@ public Object execute(String commandName, Map<String, ?> parameters) {
4039
Response response;
4140

4241
if (parameters == null || parameters.isEmpty()) {
43-
response = driver.execute(commandName, ImmutableMap.of());
42+
response = driver.execute(commandName, Map.of());
4443
} else {
4544
response = driver.execute(commandName, parameters);
4645
}

src/main/java/io/appium/java_client/CommandExecutionHelper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
package io.appium.java_client;
1818

19-
import com.google.common.collect.ImmutableMap;
2019
import org.openqa.selenium.remote.Response;
2120

2221
import javax.annotation.Nullable;
23-
import java.util.AbstractMap;
2422
import java.util.Collections;
2523
import java.util.Map;
2624

@@ -66,7 +64,7 @@ public static <T> T executeScript(ExecutesMethod executesMethod, String scriptNa
6664
public static <T> T executeScript(
6765
ExecutesMethod executesMethod, String scriptName, @Nullable Map<String, Object> args
6866
) {
69-
return execute(executesMethod, new AbstractMap.SimpleEntry<>(EXECUTE_SCRIPT, ImmutableMap.of(
67+
return execute(executesMethod, Map.entry(EXECUTE_SCRIPT, Map.of(
7068
"script", scriptName,
7169
"args", (args == null || args.isEmpty()) ? Collections.emptyList() : Collections.singletonList(args)
7270
)));

src/main/java/io/appium/java_client/ErrorCodesMobile.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package io.appium.java_client;
1919

20-
import com.google.common.collect.ImmutableMap;
2120
import org.openqa.selenium.WebDriverException;
2221
import org.openqa.selenium.remote.ErrorCodes;
2322

@@ -32,9 +31,7 @@ public class ErrorCodesMobile extends ErrorCodes {
3231

3332
public static final int NO_SUCH_CONTEXT = 35;
3433

35-
private static Map<Integer, String> statusToState =
36-
ImmutableMap.<Integer, String>builder().put(NO_SUCH_CONTEXT, "No such context found")
37-
.build();
34+
private static Map<Integer, String> statusToState = Map.of(NO_SUCH_CONTEXT, "No such context found");
3835

3936
/**
4037
* Returns the exception type that corresponds to the given {@code statusCode}. All unrecognized

src/main/java/io/appium/java_client/ExecuteCDPCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.util.HashMap;
2525
import java.util.Map;
2626

27-
import static com.google.common.base.Preconditions.checkNotNull;
2827
import static io.appium.java_client.MobileCommand.EXECUTE_GOOGLE_CDP_COMMAND;
28+
import static java.util.Objects.requireNonNull;
2929

3030
public interface ExecuteCDPCommand extends ExecutesMethod {
3131

@@ -40,7 +40,7 @@ public interface ExecuteCDPCommand extends ExecutesMethod {
4040
*/
4141
default Map<String, Object> executeCdpCommand(String command, @Nullable Map<String, Object> params) {
4242
Map<String, Object> data = new HashMap<>();
43-
data.put("cmd", checkNotNull(command));
43+
data.put("cmd", requireNonNull(command));
4444
data.put("params", params == null ? Collections.emptyMap() : params);
4545
Response response = execute(EXECUTE_GOOGLE_CDP_COMMAND, data);
4646
//noinspection unchecked

src/main/java/io/appium/java_client/ExecutesDriverScript.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.util.HashMap;
2525
import java.util.Map;
2626

27-
import static com.google.common.base.Preconditions.checkNotNull;
2827
import static io.appium.java_client.MobileCommand.EXECUTE_DRIVER_SCRIPT;
28+
import static java.util.Objects.requireNonNull;
2929

3030
public interface ExecutesDriverScript extends ExecutesMethod {
3131

@@ -46,7 +46,7 @@ public interface ExecutesDriverScript extends ExecutesMethod {
4646
*/
4747
default ScriptValue executeDriverScript(String script, @Nullable ScriptOptions options) {
4848
Map<String, Object> data = new HashMap<>();
49-
data.put("script", checkNotNull(script));
49+
data.put("script", requireNonNull(script));
5050
if (options != null) {
5151
data.putAll(options.build());
5252
}

src/main/java/io/appium/java_client/HasAppStrings.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616

1717
package io.appium.java_client;
1818

19-
import com.google.common.collect.ImmutableMap;
2019
import org.openqa.selenium.UnsupportedCommandException;
2120

22-
import java.util.AbstractMap;
2321
import java.util.Map;
2422

2523
import static io.appium.java_client.MobileCommand.GET_STRINGS;
26-
import static io.appium.java_client.MobileCommand.prepareArguments;
2724

2825
public interface HasAppStrings extends ExecutesMethod, CanRememberExtensionPresence {
2926
/**
@@ -52,14 +49,14 @@ default Map<String, String> getAppStringMap() {
5249
default Map<String, String> getAppStringMap(String language) {
5350
final String extName = "mobile: getAppStrings";
5451
try {
55-
return CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, ImmutableMap.of(
52+
return CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of(
5653
"language", language
5754
));
5855
} catch (UnsupportedCommandException e) {
5956
// TODO: Remove the fallback
6057
return CommandExecutionHelper.execute(
6158
markExtensionAbsence(extName),
62-
new AbstractMap.SimpleEntry<>(GET_STRINGS, prepareArguments("language", language))
59+
Map.entry(GET_STRINGS, Map.of("language", language))
6360
);
6461
}
6562
}
@@ -75,18 +72,17 @@ default Map<String, String> getAppStringMap(String language) {
7572
*/
7673
default Map<String, String> getAppStringMap(String language, String stringFile) {
7774
final String extName = "mobile: getAppStrings";
75+
Map<String, Object> args = Map.of(
76+
"language", language,
77+
"stringFile", stringFile
78+
);
7879
try {
79-
return CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, ImmutableMap.of(
80-
"language", language,
81-
"stringFile", stringFile
82-
));
80+
return CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, args);
8381
} catch (UnsupportedCommandException e) {
8482
// TODO: Remove the fallback
85-
String[] parameters = new String[]{"language", "stringFile"};
86-
Object[] values = new Object[]{language, stringFile};
8783
return CommandExecutionHelper.execute(
8884
markExtensionAbsence(extName),
89-
new AbstractMap.SimpleEntry<>(GET_STRINGS, prepareArguments(parameters, values))
85+
Map.entry(GET_STRINGS, args)
9086
);
9187
}
9288
}

src/main/java/io/appium/java_client/HasBrowserCheck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import org.openqa.selenium.WebDriverException;
77
import org.openqa.selenium.remote.CapabilityType;
88

9-
import static com.google.common.base.Preconditions.checkNotNull;
109
import static com.google.common.base.Strings.isNullOrEmpty;
10+
import static java.util.Objects.requireNonNull;
1111

1212
public interface HasBrowserCheck extends ExecutesMethod, HasCapabilities {
1313
/**
@@ -20,7 +20,7 @@ default boolean isBrowser() {
2020
CapabilityType.BROWSER_NAME, String.class);
2121
if (!isNullOrEmpty(browserName)) {
2222
try {
23-
return checkNotNull(
23+
return requireNonNull(
2424
CommandExecutionHelper.executeScript(this, "return !!window.navigator;")
2525
);
2626
} catch (WebDriverException ign) {

src/main/java/io/appium/java_client/HasDeviceTime.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package io.appium.java_client;
1818

19-
import com.google.common.collect.ImmutableMap;
19+
import java.util.Map;
2020

2121
public interface HasDeviceTime extends ExecutesMethod {
2222

@@ -32,7 +32,7 @@ public interface HasDeviceTime extends ExecutesMethod {
3232
*/
3333
default String getDeviceTime(String format) {
3434
return CommandExecutionHelper.executeScript(
35-
this, "mobile: getDeviceTime", ImmutableMap.of("format", format)
35+
this, "mobile: getDeviceTime", Map.of("format", format)
3636
);
3737
}
3838

src/main/java/io/appium/java_client/HasOnScreenKeyboard.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import org.openqa.selenium.UnsupportedCommandException;
44

5-
import static com.google.common.base.Preconditions.checkNotNull;
65
import static io.appium.java_client.MobileCommand.isKeyboardShownCommand;
6+
import static java.util.Objects.requireNonNull;
77

88
public interface HasOnScreenKeyboard extends ExecutesMethod, CanRememberExtensionPresence {
99

@@ -16,10 +16,10 @@ public interface HasOnScreenKeyboard extends ExecutesMethod, CanRememberExtensio
1616
default boolean isKeyboardShown() {
1717
final String extName = "mobile: isKeyboardShown";
1818
try {
19-
return checkNotNull(CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName));
19+
return requireNonNull(CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName));
2020
} catch (UnsupportedCommandException e) {
2121
// TODO: Remove the fallback
22-
return checkNotNull(
22+
return requireNonNull(
2323
CommandExecutionHelper.execute(markExtensionAbsence(extName), isKeyboardShownCommand())
2424
);
2525
}

src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
package io.appium.java_client;
1818

19-
import com.google.common.collect.ImmutableList;
20-
import com.google.common.collect.ImmutableMap;
2119
import org.openqa.selenium.UnsupportedCommandException;
2220

21+
import java.util.List;
22+
import java.util.Map;
23+
2324
import static io.appium.java_client.MobileCommand.hideKeyboardCommand;
2425

2526
public interface HidesKeyboardWithKeyName extends HidesKeyboard {
@@ -37,8 +38,8 @@ public interface HidesKeyboardWithKeyName extends HidesKeyboard {
3738
default void hideKeyboard(String keyName) {
3839
final String extName = "mobile: hideKeyboard";
3940
try {
40-
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, ImmutableMap.of(
41-
"keys", ImmutableList.of(keyName)
41+
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of(
42+
"keys", List.of(keyName)
4243
));
4344
} catch (UnsupportedCommandException e) {
4445
// TODO: Remove the fallback

0 commit comments

Comments
 (0)