Skip to content

Commit 95e4042

Browse files
author
Mykola Mokhnach
committed
Fix checkstyle issues
1 parent 5fdf0e1 commit 95e4042

8 files changed

Lines changed: 50 additions & 44 deletions

File tree

‎src/main/java/io/appium/java_client/TouchAction.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.appium.java_client;
1818

19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
1921
import com.google.common.collect.ImmutableList;
2022
import com.google.common.collect.ImmutableMap;
2123

@@ -29,8 +31,6 @@
2931

3032
import java.time.Duration;
3133

32-
import static com.google.common.base.Preconditions.checkNotNull;
33-
3434
/**
3535
* Used for Webdriver 3 touch actions
3636
* See the Webriver 3 spec

‎src/main/java/io/appium/java_client/touch/LongPressOptions.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package io.appium.java_client.touch;
1818

19-
import java.time.Duration;
20-
import java.util.Map;
21-
2219
import static com.google.common.base.Preconditions.checkArgument;
2320
import static com.google.common.base.Preconditions.checkNotNull;
2421

22+
import java.time.Duration;
23+
import java.util.Map;
24+
2525
public class LongPressOptions extends OptionsWithAbsolutePositioning<LongPressOptions> {
2626
protected Duration duration = null;
2727

‎src/main/java/io/appium/java_client/touch/OptionsWithAbsolutePositioning.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package io.appium.java_client.touch;
1818

19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
1921
import org.openqa.selenium.Point;
2022
import org.openqa.selenium.WebElement;
2123
import org.openqa.selenium.internal.HasIdentity;
2224

2325
import java.util.Map;
2426

25-
import static com.google.common.base.Preconditions.checkNotNull;
26-
2727
public abstract class OptionsWithAbsolutePositioning<T extends OptionsWithAbsolutePositioning<T>>
2828
extends ActionOptions<T> {
2929
private String elementId = null;
@@ -73,14 +73,17 @@ public T withRelativeOffset(int xOffset, int yOffset) {
7373
protected void verify() {
7474
if (elementId == null) {
7575
if (absoluteOffset == null) {
76-
throw new IllegalArgumentException("Absolute offset must be defined if 'element' option is not set");
76+
throw new IllegalArgumentException(
77+
"Absolute offset must be defined if 'element' option is not set");
7778
}
7879
if (relativeOffset != null) {
79-
throw new IllegalArgumentException("Relative offset must not be defined if 'element' option is not set");
80+
throw new IllegalArgumentException(
81+
"Relative offset must not be defined if 'element' option is not set");
8082
}
8183
} else {
8284
if (absoluteOffset != null) {
83-
throw new IllegalArgumentException("Absolute offset must not be defined if 'element' option set");
85+
throw new IllegalArgumentException(
86+
"Absolute offset must not be defined if 'element' option set");
8487
}
8588
}
8689
}

‎src/main/java/io/appium/java_client/touch/OptionsWithRelativePositioning.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package io.appium.java_client.touch;
1818

19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
1921
import org.openqa.selenium.Point;
2022
import org.openqa.selenium.WebElement;
2123
import org.openqa.selenium.internal.HasIdentity;
2224

2325
import java.util.Map;
2426

25-
import static com.google.common.base.Preconditions.checkNotNull;
26-
2727
public abstract class OptionsWithRelativePositioning<T extends OptionsWithRelativePositioning<T>>
2828
extends ActionOptions<T> {
2929
private String elementId = null;

‎src/main/java/io/appium/java_client/touch/TapOptions.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
package io.appium.java_client.touch;
1818

19-
import java.util.Map;
20-
2119
import static com.google.common.base.Preconditions.checkArgument;
2220

21+
import java.util.Map;
22+
2323
public class TapOptions extends OptionsWithAbsolutePositioning<TapOptions> {
2424
private Integer tapsCount = null;
2525

‎src/main/java/io/appium/java_client/touch/WaitOptions.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package io.appium.java_client.touch;
1818

19-
import java.time.Duration;
20-
import java.util.Map;
21-
2219
import static com.google.common.base.Preconditions.checkArgument;
2320
import static com.google.common.base.Preconditions.checkNotNull;
2421

22+
import java.time.Duration;
23+
import java.util.Map;
24+
2525
public class WaitOptions extends ActionOptions<WaitOptions> {
2626
protected Duration duration = Duration.ofMillis(0);
2727

‎src/test/java/io/appium/java_client/touch/FailsWithMatcher.java‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
package io.appium.java_client.touch;
22

3+
import static org.hamcrest.core.AllOf.allOf;
4+
import static org.hamcrest.core.IsInstanceOf.instanceOf;
5+
36
import org.hamcrest.Description;
47
import org.hamcrest.Matcher;
58
import org.hamcrest.TypeSafeMatcher;
69

7-
import static org.hamcrest.core.AllOf.allOf;
8-
import static org.hamcrest.core.IsInstanceOf.instanceOf;
9-
10-
public final class FailsWithMatcher<Ex extends Throwable>
11-
extends TypeSafeMatcher<IThrowingRunnable<Ex>> {
10+
public final class FailsWithMatcher<E extends Throwable> extends TypeSafeMatcher<IThrowingRunnable<E>> {
1211

13-
private final Matcher<? super Ex> matcher;
12+
private final Matcher<? super E> matcher;
1413

15-
private FailsWithMatcher(final Matcher<? super Ex> matcher) {
14+
private FailsWithMatcher(final Matcher<? super E> matcher) {
1615
this.matcher = matcher;
1716
}
1817

19-
public static <Ex extends Throwable> Matcher<IThrowingRunnable<Ex>> failsWith(
20-
final Class<Ex> throwableType) {
18+
public static <E extends Throwable> Matcher<IThrowingRunnable<E>> failsWith(
19+
final Class<E> throwableType) {
2120
return new FailsWithMatcher<>(instanceOf(throwableType));
2221
}
2322

24-
public static <Ex extends Throwable> Matcher<IThrowingRunnable<Ex>> failsWith(
25-
final Class<Ex> throwableType, final Matcher<? super Ex> throwableMatcher) {
23+
public static <E extends Throwable> Matcher<IThrowingRunnable<E>> failsWith(
24+
final Class<E> throwableType, final Matcher<? super E> throwableMatcher) {
2625
return new FailsWithMatcher<>(allOf(instanceOf(throwableType), throwableMatcher));
2726
}
2827

2928
@Override
30-
protected boolean matchesSafely(final IThrowingRunnable<Ex> runnable) {
29+
protected boolean matchesSafely(final IThrowingRunnable<E> runnable) {
3130
try {
3231
runnable.run();
3332
return false;

‎src/test/java/io/appium/java_client/touch/TouchOptionsTests.java‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,44 @@
44
import org.openqa.selenium.WebElement;
55
import org.openqa.selenium.internal.HasIdentity;
66

7+
import static io.appium.java_client.touch.FailsWithMatcher.failsWith;
8+
import static org.hamcrest.CoreMatchers.everyItem;
9+
import static org.hamcrest.MatcherAssert.assertThat;
10+
import static org.hamcrest.Matchers.isIn;
11+
712
import java.time.Duration;
813
import java.util.ArrayList;
914
import java.util.HashMap;
1015
import java.util.List;
1116
import java.util.Map;
1217

13-
import static io.appium.java_client.touch.FailsWithMatcher.failsWith;
14-
import static org.hamcrest.CoreMatchers.everyItem;
15-
import static org.hamcrest.MatcherAssert.assertThat;
16-
import static org.hamcrest.Matchers.isIn;
17-
1818
public class TouchOptionsTests {
19-
private static final WebElement dummyElement = new DummyElement();
19+
private static final WebElement DUMMY_ELEMENT = new DummyElement();
2020

2121
@Test
2222
public void invalidAbsolutePositionOptionsShouldFailOnBuild() throws Exception {
2323
final List<ActionOptions> invalidOptions = new ArrayList<>();
2424
invalidOptions.add(new PressOptions()
25-
.withElement(dummyElement)
25+
.withElement(DUMMY_ELEMENT)
2626
.withAbsoluteOffset(0, 0));
2727
invalidOptions.add(new LongPressOptions()
2828
.withRelativeOffset(0, 0));
2929
invalidOptions.add(new TapOptions());
3030
invalidOptions.add(new TapOptions()
3131
.withAbsoluteOffset(0, 0)
3232
.withRelativeOffset(0, 0));
33-
invalidOptions.forEach(opts -> assertThat(opts::build, failsWith(IllegalArgumentException.class)));
33+
for (ActionOptions opts : invalidOptions) {
34+
assertThat(opts::build, failsWith(IllegalArgumentException.class));
35+
}
3436
}
3537

3638
@Test
3739
public void invalidRelativePositionOptionsShouldFailOnBuild() throws Exception {
3840
final List<ActionOptions> invalidOptions = new ArrayList<>();
3941
invalidOptions.add(new MoveToOptions());
40-
invalidOptions.forEach(opts -> assertThat(opts::build, failsWith(IllegalArgumentException.class)));
42+
for (ActionOptions opts : invalidOptions) {
43+
assertThat(opts::build, failsWith(IllegalArgumentException.class));
44+
}
4145
}
4246

4347
@Test
@@ -55,12 +59,12 @@ public void invalidOptionsArgumentsShouldFailOnAltering() throws Exception {
5559
@Test
5660
public void longPressOptionsShouldBuildProperly() throws Exception {
5761
final Map<String, Object> actualOpts = new LongPressOptions()
58-
.withElement(dummyElement)
62+
.withElement(DUMMY_ELEMENT)
5963
.withRelativeOffset(0, 0)
6064
.withDuration(Duration.ofMillis(1))
6165
.build();
6266
final Map<String, Object> expectedOpts = new HashMap<>();
63-
expectedOpts.put("element", ((HasIdentity) dummyElement).getId());
67+
expectedOpts.put("element", ((HasIdentity) DUMMY_ELEMENT).getId());
6468
expectedOpts.put("x", 0);
6569
expectedOpts.put("y", 0);
6670
expectedOpts.put("duration", 1L);
@@ -85,22 +89,22 @@ public void tapOptionsShouldBuildProperly() throws Exception {
8589
@Test
8690
public void pressOptionsShouldBuildProperly() throws Exception {
8791
final Map<String, Object> actualOpts = new PressOptions()
88-
.withElement(dummyElement)
92+
.withElement(DUMMY_ELEMENT)
8993
.build();
9094
final Map<String, Object> expectedOpts = new HashMap<>();
91-
expectedOpts.put("element", ((HasIdentity) dummyElement).getId());
95+
expectedOpts.put("element", ((HasIdentity) DUMMY_ELEMENT).getId());
9296
assertThat(actualOpts.entrySet(), everyItem(isIn(expectedOpts.entrySet())));
9397
assertThat(expectedOpts.entrySet(), everyItem(isIn(actualOpts.entrySet())));
9498
}
9599

96100
@Test
97101
public void moveToOptionsShouldBuildProperly() throws Exception {
98102
final Map<String, Object> actualOpts = new MoveToOptions()
99-
.withElement(dummyElement)
103+
.withElement(DUMMY_ELEMENT)
100104
.withRelativeOffset(-1,-1)
101105
.build();
102106
final Map<String, Object> expectedOpts = new HashMap<>();
103-
expectedOpts.put("element", ((HasIdentity) dummyElement).getId());
107+
expectedOpts.put("element", ((HasIdentity) DUMMY_ELEMENT).getId());
104108
expectedOpts.put("x", -1);
105109
expectedOpts.put("y", -1);
106110
assertThat(actualOpts.entrySet(), everyItem(isIn(expectedOpts.entrySet())));

0 commit comments

Comments
 (0)