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 all 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
22 changes: 22 additions & 0 deletions src/main/java/io/appium/java_client/AppiumBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

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

public abstract class AppiumBy extends By implements Remotable {

Expand Down Expand Up @@ -253,6 +254,27 @@ 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
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private EspressoBuildConfig assignToolsVersionsField(String name, Object value)
private <R> Optional<R> getToolsVersionsFieldValue(String name) {
Optional<Map<String, Object>> toolsVersionsOptional = getOptionValue(TOOLS_VERSION);
//noinspection unchecked
return toolsVersionsOptional.map((v) -> (R) v.getOrDefault(name, null));
return toolsVersionsOptional.map(v -> (R) v.getOrDefault(name, null));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ default T setEspressoBuildConfig(EspressoBuildConfig config) {
default Optional<Either<EspressoBuildConfig, String>> getEspressoBuildConfig() {
return Optional.ofNullable(getCapability(ESPRESSO_BUILD_CONFIG_OPTION))
.map(String::valueOf)
.map((v) -> v.trim().startsWith("{")
.map(v -> v.trim().startsWith("{")
? Either.left(new EspressoBuildConfig(v))
: Either.right(v)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public interface SupportsBuildCheckOption<T extends BaseOptions<T>> extends
* Unless disable build check preference has been user-set, the capability
* is not present because the default value is false.
*
* @param BuildCheckDisabled flag for --disable-build-check.
* @param buildCheckDisabled flag for --disable-build-check.
* @return self instance for chaining.
*/
default T setBuildCheckDisabled(boolean BuildCheckDisabled) {
return amend(DISABLE_BUILD_CHECK, BuildCheckDisabled);
default T setBuildCheckDisabled(boolean buildCheckDisabled) {
return amend(DISABLE_BUILD_CHECK, buildCheckDisabled);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<OccurrenceMatchingResult> getMultiple() {
//noinspection unchecked
List<Map<String, Object>> multiple = (List<Map<String, Object>>) getCommandResult().get(MULTIPLE);
return multiple.stream()
.map((m) -> new OccurrenceMatchingResult(m, false))
.map(m -> new OccurrenceMatchingResult(m, false))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.appium.java_client.internal;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.openqa.selenium.Capabilities;

import javax.annotation.Nullable;
Expand All @@ -26,6 +28,7 @@
import java.util.List;
import java.util.function.Function;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CapabilityHelpers {
public static final String APPIUM_PREFIX = "appium:";

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/internal/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public <T> T getValue(String key, Class<T> valueType) {
* @throws ClassCastException if the retrieved value cannot be cast to `valueType` type
*/
public <T> Optional<T> getOptionalValue(String key, Class<T> valueType) {
final Properties cachedProps = cache.computeIfAbsent(configName, (k) -> {
final Properties cachedProps = cache.computeIfAbsent(configName, k -> {
try (InputStream configFileStream = getClass().getClassLoader().getResourceAsStream(configName)) {
final Properties p = new Properties();
p.load(configFileStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@

package io.appium.java_client.internal;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.openqa.selenium.WebDriverException;

import java.lang.reflect.Field;

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

/**
* Sets the given value to a private instance field.
*
* @param cls The target class or a superclass.
* @param target Target instance.
* @param cls The target class or a superclass.
* @param target Target instance.
* @param fieldName Target field name.
* @param newValue The value to be set.
* @param newValue The value to be set.
* @return The same instance for chaining.
*/
public static <T> T setPrivateFieldValue(Class<?> cls, T target, String fieldName, Object newValue) {
Expand All @@ -45,8 +48,8 @@ public static <T> T setPrivateFieldValue(Class<?> cls, T target, String fieldNam
/**
* Fetches the value of a private instance field.
*
* @param cls The target class or a superclass.
* @param target Target instance.
* @param cls The target class or a superclass.
* @param target Target instance.
* @param fieldName Target field name.
* @param fieldType Field type.
* @return The retrieved field value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.appium.java_client.internal;

import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.openqa.selenium.InvalidArgumentException;
import org.openqa.selenium.WebDriverException;

Expand All @@ -25,6 +27,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SessionHelpers {
private static final Pattern SESSION = Pattern.compile("/session/([^/]+)");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ default T setCommandTimeouts(Duration timeout) {
default Optional<Either<CommandTimeouts, Duration>> getCommandTimeouts() {
return Optional.ofNullable(getCapability(COMMAND_TIMEOUTS_OPTION))
.map(String::valueOf)
.map((v) -> v.trim().startsWith("{")
.map(v -> v.trim().startsWith("{")
? Either.left(new CommandTimeouts(v))
: Either.right(toDuration(v))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ default T setPermissions(Permissions permissions) {
*/
default Optional<Permissions> getPermissions() {
return Optional.ofNullable(getCapability(PERMISSIONS_OPTION))
.map((v) -> new Permissions(String.valueOf(v)));
.map(v -> new Permissions(String.valueOf(v)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ default T setSimulatorPasteboardAutomaticSync(PasteboardSyncState state) {
*/
default Optional<PasteboardSyncState> getSimulatorPasteboardAutomaticSync() {
return Optional.ofNullable(getCapability(SIMULATOR_PASTEBOARD_AUTOMATIC_SYNC))
.map((v) -> PasteboardSyncState.valueOf(String.valueOf(v).toUpperCase()));
.map(v -> PasteboardSyncState.valueOf(String.valueOf(v).toUpperCase()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public ProcessArguments(Map<String, Object> env) {
*/
public Map<String, Object> toMap() {
Map<String, Object> result = new HashMap<>();
Optional.ofNullable(args).ifPresent((v) -> result.put("args", v));
Optional.ofNullable(env).ifPresent((v) -> result.put("env", v));
Optional.ofNullable(args).ifPresent(v -> result.put("args", v));
Optional.ofNullable(env).ifPresent(v -> result.put("env", v));
return Collections.unmodifiableMap(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ default T setWaitForIdleTimeout(Duration timeout) {
default Optional<Duration> getWaitForIdleTimeout() {
return Optional.ofNullable(getCapability(WAIT_FOR_IDLE_TIMEOUT_OPTION))
.map(CapabilityHelpers::toDouble)
.map((d) -> toDuration((long) (d * 1000.0)));
.map(d -> toDuration((long) (d * 1000.0)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ default T setWdaEventloopIdleDelay(Duration duration) {
default Optional<Duration> getWdaEventloopIdleDelay() {
return Optional.ofNullable(getCapability(WDA_EVENTLOOP_IDLE_DELAY_OPTION))
.map(CapabilityHelpers::toDouble)
.map((d) -> toDuration((long) (d * 1000.0)));
.map(d -> toDuration((long) (d * 1000.0)));
}
}
Loading