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

Lines changed: 20 additions & 3 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)