Skip to content

fix: Fix Code style issues to match Java standards #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 54 additions & 18 deletions src/main/java/io/appium/java_client/AppiumBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

public abstract class AppiumBy extends By implements Remotable {

@Getter private final Parameters remoteParameters;
@Getter
private final Parameters remoteParameters;
private final String locatorName;

protected AppiumBy(String selector, String locatorString, String locatorName) {
Expand All @@ -37,24 +39,28 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
this.locatorName = locatorName;
}

@Override public List<WebElement> findElements(SearchContext context) {
@Override
public List<WebElement> findElements(SearchContext context) {
return context.findElements(this);
}

@Override public WebElement findElement(SearchContext context) {
@Override
public WebElement findElement(SearchContext context) {
return context.findElement(this);
}

@Override public String toString() {
@Override
public String toString() {
return String.format("%s.%s: %s", AppiumBy.class.getSimpleName(), locatorName, remoteParameters.value());
}

/**
* About Android accessibility
* https://developer.android.com/intl/ru/training/accessibility/accessible-app.html
* <a href="https://developer.android.com/intl/ru/training/accessibility/accessible-app.html">https://developer.android.com/intl/ru/training/accessibility/accessible-app.html</a>
* About iOS accessibility
* https://developer.apple.com/library/ios/documentation/UIKit/Reference/
* <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/">https://developer.apple.com/library/ios/documentation/UIKit/Reference/</a>
* UIAccessibilityIdentification_Protocol/index.html
*
* @param accessibilityId id is a convenient UI automation accessibility Id.
* @return an instance of {@link AppiumBy.ByAndroidUIAutomator}
*/
Expand All @@ -64,17 +70,19 @@ public static By accessibilityId(final String accessibilityId) {

/**
* This locator strategy is only available in Espresso Driver mode.
*
* @param dataMatcherString is a valid json string detailing hamcrest matcher for Espresso onData().
* See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
* the documentation</a> for more details
* See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
* the documentation</a> for more details.
* @return an instance of {@link AppiumBy.ByAndroidDataMatcher}
*/
public static By androidDataMatcher(final String dataMatcherString) {
return new ByAndroidDataMatcher(dataMatcherString);
}

/**
* Refer to https://developer.android.com/training/testing/ui-automator
* Refer to <a href="https://developer.android.com/training/testing/ui-automator">https://developer.android.com/training/testing/ui-automator</a>
*
* @param uiautomatorText is Android UIAutomator string
* @return an instance of {@link AppiumBy.ByAndroidUIAutomator}
*/
Expand All @@ -84,9 +92,10 @@ public static By androidUIAutomator(final String uiautomatorText) {

/**
* This locator strategy is only available in Espresso Driver mode.
*
* @param viewMatcherString is a valid json string detailing hamcrest matcher for Espresso onView().
* See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
* the documentation</a> for more details
* See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
* the documentation</a> for more details
* @return an instance of {@link AppiumBy.ByAndroidViewMatcher}
*/
public static By androidViewMatcher(final String viewMatcherString) {
Expand All @@ -95,9 +104,10 @@ public static By androidViewMatcher(final String viewMatcherString) {

/**
* This locator strategy is available in Espresso Driver mode.
* @since Appium 1.8.2 beta
*
* @param tag is a view tag string
* @return an instance of {@link ByAndroidViewTag}
* @since Appium 1.8.2 beta
*/
public static By androidViewTag(final String tag) {
return new ByAndroidViewTag(tag);
Expand All @@ -106,6 +116,7 @@ public static By androidViewTag(final String tag) {
/**
* For IOS it is the full name of the XCUI element and begins with XCUIElementType.
* For Android it is the full name of the UIAutomator2 class (e.g.: android.widget.TextView)
*
* @param selector the class name of the element
* @return an instance of {@link ByClassName}
*/
Expand All @@ -116,6 +127,7 @@ public static By className(final String selector) {
/**
* For IOS the element name.
* For Android it is the resource identifier.
*
* @param selector element id
* @return an instance of {@link ById}
*/
Expand All @@ -126,6 +138,7 @@ public static By id(final String selector) {
/**
* For IOS the element name.
* For Android it is the resource identifier.
*
* @param selector element id
* @return an instance of {@link ByName}
*/
Expand All @@ -149,24 +162,25 @@ public static By custom(final String selector) {
* This locator strategy is available only if OpenCV libraries and
* Node.js bindings are installed on the server machine.
*
* @param b64Template base64-encoded template image string. Supported image formats are the same
* as for OpenCV library.
* @return an instance of {@link ByImage}
* @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md">
* The documentation on Image Comparison Features</a>
* @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js">
* The settings available for lookup fine-tuning</a>
* @since Appium 1.8.2
* @param b64Template base64-encoded template image string. Supported image formats are the same
* as for OpenCV library.
* @return an instance of {@link ByImage}
*/
public static By image(final String b64Template) {
return new ByImage(b64Template);
}

/**
* This locator strategy is available in XCUITest Driver mode.
*
* @param iOSClassChainString is a valid class chain locator string.
* See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">
* the documentation</a> for more details
*See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">
* the documentation</a> for more details
* @return an instance of {@link AppiumBy.ByIosClassChain}
*/
public static By iOSClassChain(final String iOSClassChainString) {
Expand All @@ -175,6 +189,7 @@ public static By iOSClassChain(final String iOSClassChainString) {

/**
* This locator strategy is available in XCUITest Driver mode.
*
* @param iOSNsPredicateString is an iOS NsPredicate String
* @return an instance of {@link AppiumBy.ByIosNsPredicate}
*/
Expand Down Expand Up @@ -244,7 +259,8 @@ protected ByImage(String b64Template) {

public static class ByIosClassChain extends AppiumBy implements Serializable {
protected ByIosClassChain(String locatorString) {
super("-ios class chain", locatorString, "iOSClassChain");
super("-ios class chain", locatorString,
"iOSClassChain");
}
}

Expand All @@ -253,6 +269,26 @@ protected ByIosNsPredicate(String locatorString) {
super("-ios predicate string", locatorString, "iOSNsPredicate");
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
AppiumBy appiumBy = (AppiumBy) o;
return Objects.equals(remoteParameters, appiumBy.remoteParameters) && Objects.equals(locatorName, appiumBy.locatorName);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), remoteParameters, locatorName);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package io.appium.java_client;

import com.google.common.collect.ImmutableMap;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.openqa.selenium.remote.Response;

import javax.annotation.Nullable;
Expand All @@ -26,6 +28,7 @@

import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class CommandExecutionHelper {

@Nullable
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/appium/java_client/ErrorCodesMobile.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ErrorCodesMobile extends ErrorCodes {
* @param statusCode The status code to convert.
* @return The exception type that corresponds to the provided status
*/
@Override
public Class<? extends WebDriverException> getExceptionType(int statusCode) {
switch (statusCode) {
case NO_SUCH_CONTEXT:
Expand All @@ -60,6 +61,7 @@ public Class<? extends WebDriverException> getExceptionType(int statusCode) {
* @return The exception type that corresponds to the provided error message or {@code null} if
* there are no matching mobile exceptions.
*/
@Override
public Class<? extends WebDriverException> getExceptionType(String message) {
for (Map.Entry<Integer, String> entry : statusToState.entrySet()) {
if (message.contains(entry.getValue())) {
Expand All @@ -75,6 +77,7 @@ public Class<? extends WebDriverException> getExceptionType(String message) {
* @param thrown The thrown error.
* @return The corresponding status code for the given thrown error.
*/
@Override
public int toStatusCode(Throwable thrown) {
if (thrown instanceof NoSuchContextException) {
return NO_SUCH_CONTEXT;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/appium/java_client/InteractsWithApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ default void installApp(String appPath, @Nullable BaseInstallApplicationOptions
Map args = ImmutableMap.builder()
.put("appPath", appPath)
.putAll(Optional.ofNullable(options).map(
(opts) -> ImmutableMap.of("options", opts.build())
opts -> ImmutableMap.of("options", opts.build())
).orElseGet(ImmutableMap::of))
.build();
CommandExecutionHelper.execute(
Expand Down Expand Up @@ -169,7 +169,7 @@ default boolean removeApp(String bundleId, @Nullable BaseRemoveApplicationOption
Map args = ImmutableMap.builder()
.put("bundleId", bundleId)
.putAll(Optional.ofNullable(options).map(
(opts) -> ImmutableMap.of("options", opts.build())
opts -> ImmutableMap.of("options", opts.build())
).orElseGet(ImmutableMap::of))
.build();
//noinspection RedundantCast
Expand Down Expand Up @@ -214,7 +214,7 @@ default void activateApp(String bundleId, @Nullable BaseActivateApplicationOptio
Map args = ImmutableMap.builder()
.put("bundleId", bundleId)
.putAll(Optional.ofNullable(options).map(
(opts) -> ImmutableMap.of("options", opts.build())
opts -> ImmutableMap.of("options", opts.build())
).orElseGet(ImmutableMap::of))
.build();
CommandExecutionHelper.execute(
Expand Down Expand Up @@ -290,7 +290,7 @@ default boolean terminateApp(String bundleId, @Nullable BaseTerminateApplication
Map args = ImmutableMap.builder()
.put("bundleId", bundleId)
.putAll(Optional.ofNullable(options).map(
(opts) -> ImmutableMap.of("options", opts.build())
opts -> ImmutableMap.of("options", opts.build())
).orElseGet(ImmutableMap::of))
.build();
//noinspection RedundantCast
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/appium/java_client/LocksDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ default void unlockDevice() {
final String extName = "mobile: unlock";
try {
//noinspection ConstantConditions
if (!(Boolean) CommandExecutionHelper.executeScript(assertExtensionExists(extName), "mobile: isLocked")) {
if (!Boolean.parseBoolean(CommandExecutionHelper.executeScript(assertExtensionExists(extName),
"mobile: isLocked"))) {
return;
}
CommandExecutionHelper.executeScript(this, extName);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/appium/java_client/ScreenshotState.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private ScreenshotState checkState(Function<Double, Boolean> checkerFunc, Durati
* @throws ScreenshotComparisonError if {@link #remember()} method has not been invoked yet
*/
public ScreenshotState verifyChanged(Duration timeout, double minScore) {
return checkState((x) -> x < minScore, timeout);
return checkState(x -> x < minScore, timeout);
}

/**
Expand All @@ -190,7 +190,7 @@ public ScreenshotState verifyChanged(Duration timeout, double minScore) {
* @throws ScreenshotComparisonError if {@link #remember()} method has not been invoked yet
*/
public ScreenshotState verifyNotChanged(Duration timeout, double minScore) {
return checkState((x) -> x >= minScore, timeout);
return checkState(x -> x >= minScore, timeout);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/appium/java_client/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public enum Setting {
this.name = name;
}

@Override
public String toString() {
return this.name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public IntentOptions withEi(Map<String, Integer> ei) {
private <T> Map<String, T> convertMapValues(Map<String, Object> map, Function<String, T> converter) {
return map.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey, (entry) -> converter.apply(String.valueOf(entry.getValue())))
Map.Entry::getKey, entry -> converter.apply(String.valueOf(entry.getValue())))
);
}

Expand All @@ -272,7 +272,7 @@ private <T> Map<String, T> convertMapValues(Map<String, Object> map, Function<St
*/
public Optional<Map<String, Integer>> getEi() {
Optional<Map<String, Object>> value = getOptionValue("ei");
return value.map((v) -> convertMapValues(v, Integer::parseInt));
return value.map(v -> convertMapValues(v, Integer::parseInt));
}

/**
Expand All @@ -292,7 +292,7 @@ public IntentOptions withEl(Map<String, Long> el) {
*/
public Optional<Map<String, Long>> getEl() {
Optional<Map<String, Object>> value = getOptionValue("el");
return value.map((v) -> convertMapValues(v, Long::parseLong));
return value.map(v -> convertMapValues(v, Long::parseLong));
}

/**
Expand All @@ -312,7 +312,7 @@ public IntentOptions withEf(Map<String, Float> ef) {
*/
public Optional<Map<String, Float>> getEf() {
Optional<Map<String, Object>> value = getOptionValue("ef");
return value.map((v) -> convertMapValues(v, Float::parseFloat));
return value.map(v -> convertMapValues(v, Float::parseFloat));
}

/**
Expand Down Expand Up @@ -356,7 +356,7 @@ public Optional<Map<String, String>> getEcn() {
private static Map<String, String> mergeValues(Map<String, ?> map) {
return map.entrySet().stream()
.collect(
Collectors.toMap(Map.Entry::getKey, (entry) -> ((List<?>) entry.getValue()).stream()
Collectors.toMap(Map.Entry::getKey, entry -> ((List<?>) entry.getValue()).stream()
.map(String::valueOf)
.collect(Collectors.joining(",")))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ default T setActivityOptions(ActivityOptions options) {
default Optional<ActivityOptions> getActivityOptions() {
//noinspection unchecked
return Optional.ofNullable(getCapability(ACTIVITY_OPTIONS_OPTION))
.map((v) -> new ActivityOptions((Map<String, Object>) v));
.map(v -> new ActivityOptions((Map<String, Object>) v));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ default T setIntentOptions(IntentOptions options) {
default Optional<IntentOptions> getIntentOptions() {
//noinspection unchecked
return Optional.ofNullable(getCapability(INTENT_OPTIONS_OPTION))
.map((v) -> new IntentOptions((Map<String, Object>) v));
.map(v -> new IntentOptions((Map<String, Object>) v));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ default T setAvdArgs(String args) {
default Optional<Either<List<String>, String>> getAvdArgs() {
//noinspection unchecked
return Optional.ofNullable(getCapability(AVD_ARGS_OPTION))
.map((v) -> v instanceof List
.map(v -> v instanceof List
? Either.left((List<String>) v)
: Either.right(String.valueOf(v))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ default T setAvdEnv(Map<String, Object> env) {
default Optional<Map<String, Object>> getAvdEnv() {
//noinspection unchecked
return Optional.ofNullable(getCapability(AVD_ENV_OPTION))
.map((v) -> (Map<String, Object>) v);
.map(v -> (Map<String, Object>) v);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ default T setAppLocale(AppLocale locale) {
default Optional<AppLocale> getAppLocale() {
//noinspection unchecked
return Optional.ofNullable(getCapability(APP_LOCALE_OPTION))
.map((v) -> new AppLocale((Map<String, Object>) v));
.map(v -> new AppLocale((Map<String, Object>) v));
}
}
Loading