Skip to content

Commit 5afab90

Browse files
Java code conventions fixes
1 parent 692e3a0 commit 5afab90

File tree

51 files changed

+141
-78
lines changed

Some content is hidden

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

51 files changed

+141
-78
lines changed

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

+20-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package io.appium.java_client;
1818

19+
import lombok.AccessLevel;
1920
import lombok.Getter;
21+
import lombok.NoArgsConstructor;
2022
import org.apache.commons.lang3.Validate;
2123
import org.openqa.selenium.By;
2224
import org.openqa.selenium.By.Remotable;
@@ -25,6 +27,7 @@
2527

2628
import java.io.Serializable;
2729
import java.util.List;
30+
import java.util.Objects;
2831

2932
public abstract class AppiumBy extends By implements Remotable {
3033

@@ -51,9 +54,9 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
5154

5255
/**
5356
* About Android accessibility
54-
* https://developer.android.com/intl/ru/training/accessibility/accessible-app.html
57+
* <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>
5558
* About iOS accessibility
56-
* https://developer.apple.com/library/ios/documentation/UIKit/Reference/
59+
* <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/">https://developer.apple.com/library/ios/documentation/UIKit/Reference/</a>
5760
* UIAccessibilityIdentification_Protocol/index.html
5861
* @param accessibilityId id is a convenient UI automation accessibility Id.
5962
* @return an instance of {@link AppiumBy.ByAndroidUIAutomator}
@@ -74,7 +77,7 @@ public static By androidDataMatcher(final String dataMatcherString) {
7477
}
7578

7679
/**
77-
* Refer to https://developer.android.com/training/testing/ui-automator
80+
* Refer to <a href="https://developer.android.com/training/testing/ui-automator">https://developer.android.com/training/testing/ui-automator</a>
7881
* @param uiautomatorText is Android UIAutomator string
7982
* @return an instance of {@link AppiumBy.ByAndroidUIAutomator}
8083
*/
@@ -253,6 +256,20 @@ protected ByIosNsPredicate(String locatorString) {
253256
super("-ios predicate string", locatorString, "iOSNsPredicate");
254257
}
255258
}
259+
260+
@Override
261+
public boolean equals(Object o) {
262+
if (this == o) return true;
263+
if (o == null || getClass() != o.getClass()) return false;
264+
if (!super.equals(o)) return false;
265+
AppiumBy appiumBy = (AppiumBy) o;
266+
return Objects.equals(remoteParameters, appiumBy.remoteParameters) && Objects.equals(locatorName, appiumBy.locatorName);
267+
}
268+
269+
@Override
270+
public int hashCode() {
271+
return Objects.hash(super.hashCode(), remoteParameters, locatorName);
272+
}
256273
}
257274

258275

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

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package io.appium.java_client;
1818

1919
import com.google.common.collect.ImmutableMap;
20+
import lombok.AccessLevel;
21+
import lombok.NoArgsConstructor;
2022
import org.openqa.selenium.remote.Response;
2123

2224
import javax.annotation.Nullable;
@@ -26,6 +28,7 @@
2628

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

31+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2932
public final class CommandExecutionHelper {
3033

3134
@Nullable

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

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class ErrorCodesMobile extends ErrorCodes {
4343
* @param statusCode The status code to convert.
4444
* @return The exception type that corresponds to the provided status
4545
*/
46+
@Override
4647
public Class<? extends WebDriverException> getExceptionType(int statusCode) {
4748
switch (statusCode) {
4849
case NO_SUCH_CONTEXT:
@@ -60,6 +61,7 @@ public Class<? extends WebDriverException> getExceptionType(int statusCode) {
6061
* @return The exception type that corresponds to the provided error message or {@code null} if
6162
* there are no matching mobile exceptions.
6263
*/
64+
@Override
6365
public Class<? extends WebDriverException> getExceptionType(String message) {
6466
for (Map.Entry<Integer, String> entry : statusToState.entrySet()) {
6567
if (message.contains(entry.getValue())) {
@@ -75,6 +77,7 @@ public Class<? extends WebDriverException> getExceptionType(String message) {
7577
* @param thrown The thrown error.
7678
* @return The corresponding status code for the given thrown error.
7779
*/
80+
@Override
7881
public int toStatusCode(Throwable thrown) {
7982
if (thrown instanceof NoSuchContextException) {
8083
return NO_SUCH_CONTEXT;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ default void installApp(String appPath, @Nullable BaseInstallApplicationOptions
7575
Map args = ImmutableMap.builder()
7676
.put("appPath", appPath)
7777
.putAll(Optional.ofNullable(options).map(
78-
(opts) -> ImmutableMap.of("options", opts.build())
78+
opts -> ImmutableMap.of("options", opts.build())
7979
).orElseGet(ImmutableMap::of))
8080
.build();
8181
CommandExecutionHelper.execute(
@@ -169,7 +169,7 @@ default boolean removeApp(String bundleId, @Nullable BaseRemoveApplicationOption
169169
Map args = ImmutableMap.builder()
170170
.put("bundleId", bundleId)
171171
.putAll(Optional.ofNullable(options).map(
172-
(opts) -> ImmutableMap.of("options", opts.build())
172+
opts -> ImmutableMap.of("options", opts.build())
173173
).orElseGet(ImmutableMap::of))
174174
.build();
175175
//noinspection RedundantCast
@@ -214,7 +214,7 @@ default void activateApp(String bundleId, @Nullable BaseActivateApplicationOptio
214214
Map args = ImmutableMap.builder()
215215
.put("bundleId", bundleId)
216216
.putAll(Optional.ofNullable(options).map(
217-
(opts) -> ImmutableMap.of("options", opts.build())
217+
opts -> ImmutableMap.of("options", opts.build())
218218
).orElseGet(ImmutableMap::of))
219219
.build();
220220
CommandExecutionHelper.execute(
@@ -290,7 +290,7 @@ default boolean terminateApp(String bundleId, @Nullable BaseTerminateApplication
290290
Map args = ImmutableMap.builder()
291291
.put("bundleId", bundleId)
292292
.putAll(Optional.ofNullable(options).map(
293-
(opts) -> ImmutableMap.of("options", opts.build())
293+
opts -> ImmutableMap.of("options", opts.build())
294294
).orElseGet(ImmutableMap::of))
295295
.build();
296296
//noinspection RedundantCast

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ default void unlockDevice() {
6464
final String extName = "mobile: unlock";
6565
try {
6666
//noinspection ConstantConditions
67-
if (!(Boolean) CommandExecutionHelper.executeScript(assertExtensionExists(extName), "mobile: isLocked")) {
67+
if (!Boolean.parseBoolean(CommandExecutionHelper.executeScript(assertExtensionExists(extName), "mobile: isLocked"))) {
6868
return;
6969
}
7070
CommandExecutionHelper.executeScript(this, extName);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private ScreenshotState checkState(Function<Double, Boolean> checkerFunc, Durati
175175
* @throws ScreenshotComparisonError if {@link #remember()} method has not been invoked yet
176176
*/
177177
public ScreenshotState verifyChanged(Duration timeout, double minScore) {
178-
return checkState((x) -> x < minScore, timeout);
178+
return checkState(x -> x < minScore, timeout);
179179
}
180180

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

196196
/**

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

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public enum Setting {
6565
this.name = name;
6666
}
6767

68+
@Override
6869
public String toString() {
6970
return this.name;
7071
}

src/main/java/io/appium/java_client/android/options/app/IntentOptions.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public IntentOptions withEi(Map<String, Integer> ei) {
261261
private <T> Map<String, T> convertMapValues(Map<String, Object> map, Function<String, T> converter) {
262262
return map.entrySet().stream()
263263
.collect(Collectors.toMap(
264-
Map.Entry::getKey, (entry) -> converter.apply(String.valueOf(entry.getValue())))
264+
Map.Entry::getKey, entry -> converter.apply(String.valueOf(entry.getValue())))
265265
);
266266
}
267267

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

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

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

318318
/**
@@ -356,7 +356,7 @@ public Optional<Map<String, String>> getEcn() {
356356
private static Map<String, String> mergeValues(Map<String, ?> map) {
357357
return map.entrySet().stream()
358358
.collect(
359-
Collectors.toMap(Map.Entry::getKey, (entry) -> ((List<?>) entry.getValue()).stream()
359+
Collectors.toMap(Map.Entry::getKey, entry -> ((List<?>) entry.getValue()).stream()
360360
.map(String::valueOf)
361361
.collect(Collectors.joining(",")))
362362
);

src/main/java/io/appium/java_client/android/options/app/SupportsActivityOptionsOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ default T setActivityOptions(ActivityOptions options) {
4848
default Optional<ActivityOptions> getActivityOptions() {
4949
//noinspection unchecked
5050
return Optional.ofNullable(getCapability(ACTIVITY_OPTIONS_OPTION))
51-
.map((v) -> new ActivityOptions((Map<String, Object>) v));
51+
.map(v -> new ActivityOptions((Map<String, Object>) v));
5252
}
5353
}

src/main/java/io/appium/java_client/android/options/app/SupportsIntentOptionsOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ default T setIntentOptions(IntentOptions options) {
4848
default Optional<IntentOptions> getIntentOptions() {
4949
//noinspection unchecked
5050
return Optional.ofNullable(getCapability(INTENT_OPTIONS_OPTION))
51-
.map((v) -> new IntentOptions((Map<String, Object>) v));
51+
.map(v -> new IntentOptions((Map<String, Object>) v));
5252
}
5353
}

src/main/java/io/appium/java_client/android/options/avd/SupportsAvdArgsOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ default T setAvdArgs(String args) {
5656
default Optional<Either<List<String>, String>> getAvdArgs() {
5757
//noinspection unchecked
5858
return Optional.ofNullable(getCapability(AVD_ARGS_OPTION))
59-
.map((v) -> v instanceof List
59+
.map(v -> v instanceof List
6060
? Either.left((List<String>) v)
6161
: Either.right(String.valueOf(v))
6262
);

src/main/java/io/appium/java_client/android/options/avd/SupportsAvdEnvOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ default T setAvdEnv(Map<String, Object> env) {
4545
default Optional<Map<String, Object>> getAvdEnv() {
4646
//noinspection unchecked
4747
return Optional.ofNullable(getCapability(AVD_ENV_OPTION))
48-
.map((v) -> (Map<String, Object>) v);
48+
.map(v -> (Map<String, Object>) v);
4949
}
5050
}

src/main/java/io/appium/java_client/android/options/localization/SupportsAppLocaleOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ default T setAppLocale(AppLocale locale) {
5151
default Optional<AppLocale> getAppLocale() {
5252
//noinspection unchecked
5353
return Optional.ofNullable(getCapability(APP_LOCALE_OPTION))
54-
.map((v) -> new AppLocale((Map<String, Object>) v));
54+
.map(v -> new AppLocale((Map<String, Object>) v));
5555
}
5656
}

src/main/java/io/appium/java_client/android/options/server/EspressoBuildConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private EspressoBuildConfig assignToolsVersionsField(String name, Object value)
5151
private <R> Optional<R> getToolsVersionsFieldValue(String name) {
5252
Optional<Map<String, Object>> toolsVersionsOptional = getOptionValue(TOOLS_VERSION);
5353
//noinspection unchecked
54-
return toolsVersionsOptional.map((v) -> (R) v.getOrDefault(name, null));
54+
return toolsVersionsOptional.map(v -> (R) v.getOrDefault(name, null));
5555
}
5656

5757
/**

src/main/java/io/appium/java_client/android/options/server/SupportsEspressoBuildConfigOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ default T setEspressoBuildConfig(EspressoBuildConfig config) {
6161
default Optional<Either<EspressoBuildConfig, String>> getEspressoBuildConfig() {
6262
return Optional.ofNullable(getCapability(ESPRESSO_BUILD_CONFIG_OPTION))
6363
.map(String::valueOf)
64-
.map((v) -> v.trim().startsWith("{")
64+
.map(v -> v.trim().startsWith("{")
6565
? Either.left(new EspressoBuildConfig(v))
6666
: Either.right(v)
6767
);

src/main/java/io/appium/java_client/chromium/options/SupportsBuildCheckOption.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public interface SupportsBuildCheckOption<T extends BaseOptions<T>> extends
3333
* Unless disable build check preference has been user-set, the capability
3434
* is not present because the default value is false.
3535
*
36-
* @param BuildCheckDisabled flag for --disable-build-check.
36+
* @param buildCheckDisabled flag for --disable-build-check.
3737
* @return self instance for chaining.
3838
*/
39-
default T setBuildCheckDisabled(boolean BuildCheckDisabled) {
40-
return amend(DISABLE_BUILD_CHECK, BuildCheckDisabled);
39+
default T setBuildCheckDisabled(boolean buildCheckDisabled) {
40+
return amend(DISABLE_BUILD_CHECK, buildCheckDisabled);
4141
}
4242

4343
/**

src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class ComparisonResult {
3434

3535
@Getter(AccessLevel.PROTECTED) private final Map<String, Object> commandResult;
3636

37-
public ComparisonResult(Map<String, Object> commandResult) {
37+
protected ComparisonResult(Map<String, Object> commandResult) {
3838
this.commandResult = commandResult;
3939
}
4040

src/main/java/io/appium/java_client/imagecomparison/OccurrenceMatchingResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public List<OccurrenceMatchingResult> getMultiple() {
6565
//noinspection unchecked
6666
List<Map<String, Object>> multiple = (List<Map<String, Object>>) getCommandResult().get(MULTIPLE);
6767
return multiple.stream()
68-
.map((m) -> new OccurrenceMatchingResult(m, false))
68+
.map(m -> new OccurrenceMatchingResult(m, false))
6969
.collect(Collectors.toList());
7070
}
7171
}

src/main/java/io/appium/java_client/internal/CapabilityHelpers.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.appium.java_client.internal;
1818

19+
import lombok.AccessLevel;
20+
import lombok.NoArgsConstructor;
1921
import org.openqa.selenium.Capabilities;
2022

2123
import javax.annotation.Nullable;
@@ -25,7 +27,7 @@
2527
import java.util.ArrayList;
2628
import java.util.List;
2729
import java.util.function.Function;
28-
30+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2931
public class CapabilityHelpers {
3032
public static final String APPIUM_PREFIX = "appium:";
3133

src/main/java/io/appium/java_client/internal/Config.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public <T> T getValue(String key, Class<T> valueType) {
5858
* @throws ClassCastException if the retrieved value cannot be cast to `valueType` type
5959
*/
6060
public <T> Optional<T> getOptionalValue(String key, Class<T> valueType) {
61-
final Properties cachedProps = cache.computeIfAbsent(configName, (k) -> {
61+
final Properties cachedProps = cache.computeIfAbsent(configName, k -> {
6262
try (InputStream configFileStream = getClass().getClassLoader().getResourceAsStream(configName)) {
6363
final Properties p = new Properties();
6464
p.load(configFileStream);

src/main/java/io/appium/java_client/internal/ReflectionHelpers.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
package io.appium.java_client.internal;
1818

19+
import lombok.AccessLevel;
20+
import lombok.NoArgsConstructor;
1921
import org.openqa.selenium.WebDriverException;
2022

2123
import java.lang.reflect.Field;
22-
24+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2325
public class ReflectionHelpers {
2426

2527
/**

src/main/java/io/appium/java_client/internal/SessionHelpers.java

+3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package io.appium.java_client.internal;
1818

19+
import lombok.AccessLevel;
1920
import lombok.Data;
21+
import lombok.NoArgsConstructor;
2022
import org.openqa.selenium.InvalidArgumentException;
2123
import org.openqa.selenium.WebDriverException;
2224

@@ -25,6 +27,7 @@
2527
import java.util.regex.Matcher;
2628
import java.util.regex.Pattern;
2729

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

src/main/java/io/appium/java_client/ios/options/other/SupportsCommandTimeoutsOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ default T setCommandTimeouts(Duration timeout) {
6262
default Optional<Either<CommandTimeouts, Duration>> getCommandTimeouts() {
6363
return Optional.ofNullable(getCapability(COMMAND_TIMEOUTS_OPTION))
6464
.map(String::valueOf)
65-
.map((v) -> v.trim().startsWith("{")
65+
.map(v -> v.trim().startsWith("{")
6666
? Either.left(new CommandTimeouts(v))
6767
: Either.right(toDuration(v))
6868
);

src/main/java/io/appium/java_client/ios/options/simulator/SupportsPermissionsOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ default T setPermissions(Permissions permissions) {
4444
*/
4545
default Optional<Permissions> getPermissions() {
4646
return Optional.ofNullable(getCapability(PERMISSIONS_OPTION))
47-
.map((v) -> new Permissions(String.valueOf(v)));
47+
.map(v -> new Permissions(String.valueOf(v)));
4848
}
4949
}

src/main/java/io/appium/java_client/ios/options/simulator/SupportsSimulatorPasteboardAutomaticSyncOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ default T setSimulatorPasteboardAutomaticSync(PasteboardSyncState state) {
4747
*/
4848
default Optional<PasteboardSyncState> getSimulatorPasteboardAutomaticSync() {
4949
return Optional.ofNullable(getCapability(SIMULATOR_PASTEBOARD_AUTOMATIC_SYNC))
50-
.map((v) -> PasteboardSyncState.valueOf(String.valueOf(v).toUpperCase()));
50+
.map(v -> PasteboardSyncState.valueOf(String.valueOf(v).toUpperCase()));
5151
}
5252
}

0 commit comments

Comments
 (0)