44import org .openqa .selenium .WebElement ;
55import 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+
712import java .time .Duration ;
813import java .util .ArrayList ;
914import java .util .HashMap ;
1015import java .util .List ;
1116import 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-
1818public 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