From c03d7164ebff5646f2962691463c9943e36842ee Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 14 Apr 2023 08:49:44 +0200 Subject: [PATCH] refactor: Switch the time getter to use mobile extensions --- .../java_client/CommandExecutionHelper.java | 6 ++---- .../io/appium/java_client/HasDeviceTime.java | 17 +++-------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/appium/java_client/CommandExecutionHelper.java b/src/main/java/io/appium/java_client/CommandExecutionHelper.java index 5290f319a..e0a379e17 100644 --- a/src/main/java/io/appium/java_client/CommandExecutionHelper.java +++ b/src/main/java/io/appium/java_client/CommandExecutionHelper.java @@ -38,10 +38,8 @@ public static T execute(ExecutesMethod executesMethod, String command) { } private static T handleResponse(Response response) { - if (response != null) { - return (T) response.getValue(); - } - return null; + //noinspection unchecked + return response == null ? null : (T) response.getValue(); } public static T executeScript(ExecutesMethod executesMethod, String scriptName) { diff --git a/src/main/java/io/appium/java_client/HasDeviceTime.java b/src/main/java/io/appium/java_client/HasDeviceTime.java index fb9fc59b6..f29e3f3f1 100644 --- a/src/main/java/io/appium/java_client/HasDeviceTime.java +++ b/src/main/java/io/appium/java_client/HasDeviceTime.java @@ -16,14 +16,7 @@ package io.appium.java_client; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import org.openqa.selenium.remote.DriverCommand; -import org.openqa.selenium.remote.Response; - -import java.util.Map; - -import static io.appium.java_client.MobileCommand.GET_DEVICE_TIME; public interface HasDeviceTime extends ExecutesMethod { @@ -38,12 +31,9 @@ public interface HasDeviceTime extends ExecutesMethod { * @return Device time string */ default String getDeviceTime(String format) { - Map params = ImmutableMap.of( - "script", "mobile: getDeviceTime", - "args", ImmutableList.of(ImmutableMap.of("format", format)) + return CommandExecutionHelper.executeScript( + this, "mobile: getDeviceTime", ImmutableMap.of("format", format) ); - Response response = execute(DriverCommand.EXECUTE_SCRIPT, params); - return response.getValue().toString(); } /** @@ -53,7 +43,6 @@ default String getDeviceTime(String format) { * @return Device time string */ default String getDeviceTime() { - Response response = execute(GET_DEVICE_TIME); - return response.getValue().toString(); + return CommandExecutionHelper.executeScript(this, "mobile: getDeviceTime"); } }