16
16
17
17
package io .appium .java_client ;
18
18
19
- import com .google .common .collect .ImmutableMap ;
20
19
import io .appium .java_client .appmanagement .ApplicationState ;
21
20
import io .appium .java_client .appmanagement .BaseActivateApplicationOptions ;
22
21
import io .appium .java_client .appmanagement .BaseInstallApplicationOptions ;
28
27
29
28
import javax .annotation .Nullable ;
30
29
import java .time .Duration ;
31
- import java .util .Collections ;
30
+ import java .util .HashMap ;
32
31
import java .util .Map ;
33
- import java .util .Optional ;
34
32
35
33
import static io .appium .java_client .MobileCommand .ACTIVATE_APP ;
36
34
import static io .appium .java_client .MobileCommand .INSTALL_APP ;
40
38
import static io .appium .java_client .MobileCommand .RUN_APP_IN_BACKGROUND ;
41
39
import static io .appium .java_client .MobileCommand .TERMINATE_APP ;
42
40
import static java .util .Objects .requireNonNull ;
41
+ import static java .util .Optional .ofNullable ;
43
42
44
43
@ SuppressWarnings ({"rawtypes" , "unchecked" })
45
44
public interface InteractsWithApps extends ExecutesMethod , CanRememberExtensionPresence {
@@ -63,23 +62,17 @@ default void installApp(String appPath) {
63
62
default void installApp (String appPath , @ Nullable BaseInstallApplicationOptions options ) {
64
63
final String extName = "mobile: installApp" ;
65
64
try {
66
- Map <String , Object > args = ImmutableMap .<String , Object >builder ()
67
- .put ("app" , appPath )
68
- .put ("appPath" , appPath )
69
- .putAll (Optional .ofNullable (options ).map (BaseOptions ::build ).orElseGet (Collections ::emptyMap ))
70
- .build ();
65
+ var args = new HashMap <String , Object >();
66
+ args .put ("app" , appPath );
67
+ args .put ("appPath" , appPath );
68
+ ofNullable (options ).map (BaseOptions ::build ).ifPresent (args ::putAll );
71
69
CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args );
72
70
} catch (UnsupportedCommandException | InvalidArgumentException e ) {
73
71
// TODO: Remove the fallback
74
- Map args = ImmutableMap .builder ()
75
- .put ("appPath" , appPath )
76
- .putAll (Optional .ofNullable (options ).map (
77
- opts -> Map .of ("options" , opts .build ())
78
- ).orElseGet (Map ::of ))
79
- .build ();
80
- CommandExecutionHelper .execute (
81
- markExtensionAbsence (extName ), Map .entry (INSTALL_APP , args )
82
- );
72
+ var args = new HashMap <String , Object >();
73
+ args .put ("appPath" , appPath );
74
+ ofNullable (options ).map (BaseOptions ::build ).ifPresent (opts -> args .put ("options" , opts ));
75
+ CommandExecutionHelper .execute (markExtensionAbsence (extName ), Map .entry (INSTALL_APP , args ));
83
76
}
84
77
}
85
78
@@ -153,22 +146,18 @@ default boolean removeApp(String bundleId) {
153
146
default boolean removeApp (String bundleId , @ Nullable BaseRemoveApplicationOptions options ) {
154
147
final String extName = "mobile: removeApp" ;
155
148
try {
156
- Map <String , Object > args = ImmutableMap .<String , Object >builder ()
157
- .put ("bundleId" , bundleId )
158
- .put ("appId" , bundleId )
159
- .putAll (Optional .ofNullable (options ).map (BaseOptions ::build ).orElseGet (Collections ::emptyMap ))
160
- .build ();
149
+ var args = new HashMap <String , Object >();
150
+ args .put ("bundleId" , bundleId );
151
+ args .put ("appId" , bundleId );
152
+ ofNullable (options ).map (BaseOptions ::build ).ifPresent (args ::putAll );
161
153
return requireNonNull (
162
154
CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args )
163
155
);
164
156
} catch (UnsupportedCommandException | InvalidArgumentException e ) {
165
157
// TODO: Remove the fallback
166
- Map args = ImmutableMap .builder ()
167
- .put ("bundleId" , bundleId )
168
- .putAll (Optional .ofNullable (options ).map (
169
- opts -> Map .of ("options" , opts .build ())
170
- ).orElseGet (Map ::of ))
171
- .build ();
158
+ var args = new HashMap <String , Object >();
159
+ args .put ("bundleId" , bundleId );
160
+ ofNullable (options ).map (BaseOptions ::build ).ifPresent (opts -> args .put ("options" , opts ));
172
161
//noinspection RedundantCast
173
162
return requireNonNull (
174
163
(Boolean ) CommandExecutionHelper .execute (
@@ -200,23 +189,17 @@ default void activateApp(String bundleId) {
200
189
default void activateApp (String bundleId , @ Nullable BaseActivateApplicationOptions options ) {
201
190
final String extName = "mobile: activateApp" ;
202
191
try {
203
- Map <String , Object > args = ImmutableMap .<String , Object >builder ()
204
- .put ("bundleId" , bundleId )
205
- .put ("appId" , bundleId )
206
- .putAll (Optional .ofNullable (options ).map (BaseOptions ::build ).orElseGet (Collections ::emptyMap ))
207
- .build ();
192
+ var args = new HashMap <String , Object >();
193
+ args .put ("bundleId" , bundleId );
194
+ args .put ("appId" , bundleId );
195
+ ofNullable (options ).map (BaseOptions ::build ).ifPresent (args ::putAll );
208
196
CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args );
209
197
} catch (UnsupportedCommandException | InvalidArgumentException e ) {
210
198
// TODO: Remove the fallback
211
- Map args = ImmutableMap .builder ()
212
- .put ("bundleId" , bundleId )
213
- .putAll (Optional .ofNullable (options ).map (
214
- opts -> Map .of ("options" , opts .build ())
215
- ).orElseGet (Map ::of ))
216
- .build ();
217
- CommandExecutionHelper .execute (
218
- markExtensionAbsence (extName ), Map .entry (ACTIVATE_APP , args )
219
- );
199
+ var args = new HashMap <String , Object >();
200
+ args .put ("bundleId" , bundleId );
201
+ ofNullable (options ).map (BaseOptions ::build ).ifPresent (opts -> args .put ("options" , opts ));
202
+ CommandExecutionHelper .execute (markExtensionAbsence (extName ), Map .entry (ACTIVATE_APP , args ));
220
203
}
221
204
}
222
205
@@ -274,22 +257,18 @@ default boolean terminateApp(String bundleId) {
274
257
default boolean terminateApp (String bundleId , @ Nullable BaseTerminateApplicationOptions options ) {
275
258
final String extName = "mobile: terminateApp" ;
276
259
try {
277
- Map <String , Object > args = ImmutableMap .<String , Object >builder ()
278
- .put ("bundleId" , bundleId )
279
- .put ("appId" , bundleId )
280
- .putAll (Optional .ofNullable (options ).map (BaseOptions ::build ).orElseGet (Collections ::emptyMap ))
281
- .build ();
260
+ var args = new HashMap <String , Object >();
261
+ args .put ("bundleId" , bundleId );
262
+ args .put ("appId" , bundleId );
263
+ ofNullable (options ).map (BaseOptions ::build ).ifPresent (args ::putAll );
282
264
return requireNonNull (
283
265
CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args )
284
266
);
285
267
} catch (UnsupportedCommandException | InvalidArgumentException e ) {
286
268
// TODO: Remove the fallback
287
- Map args = ImmutableMap .builder ()
288
- .put ("bundleId" , bundleId )
289
- .putAll (Optional .ofNullable (options ).map (
290
- opts -> Map .of ("options" , opts .build ())
291
- ).orElseGet (Map ::of ))
292
- .build ();
269
+ var args = new HashMap <String , Object >();
270
+ args .put ("bundleId" , bundleId );
271
+ ofNullable (options ).map (BaseOptions ::build ).ifPresent (opts -> args .put ("options" , opts ));
293
272
//noinspection RedundantCast
294
273
return requireNonNull (
295
274
(Boolean ) CommandExecutionHelper .execute (
0 commit comments