1616
1717package io .appium .java_client ;
1818
19- import com .google .common .collect .ImmutableMap ;
2019import io .appium .java_client .appmanagement .ApplicationState ;
2120import io .appium .java_client .appmanagement .BaseActivateApplicationOptions ;
2221import io .appium .java_client .appmanagement .BaseInstallApplicationOptions ;
2827
2928import javax .annotation .Nullable ;
3029import java .time .Duration ;
31- import java .util .Collections ;
30+ import java .util .HashMap ;
3231import java .util .Map ;
33- import java .util .Optional ;
3432
3533import static io .appium .java_client .MobileCommand .ACTIVATE_APP ;
3634import static io .appium .java_client .MobileCommand .INSTALL_APP ;
4038import static io .appium .java_client .MobileCommand .RUN_APP_IN_BACKGROUND ;
4139import static io .appium .java_client .MobileCommand .TERMINATE_APP ;
4240import static java .util .Objects .requireNonNull ;
41+ import static java .util .Optional .ofNullable ;
4342
4443@ SuppressWarnings ({"rawtypes" , "unchecked" })
4544public interface InteractsWithApps extends ExecutesMethod , CanRememberExtensionPresence {
@@ -63,23 +62,17 @@ default void installApp(String appPath) {
6362 default void installApp (String appPath , @ Nullable BaseInstallApplicationOptions options ) {
6463 final String extName = "mobile: installApp" ;
6564 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 );
7169 CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args );
7270 } catch (UnsupportedCommandException | InvalidArgumentException e ) {
7371 // 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 ));
8376 }
8477 }
8578
@@ -153,22 +146,18 @@ default boolean removeApp(String bundleId) {
153146 default boolean removeApp (String bundleId , @ Nullable BaseRemoveApplicationOptions options ) {
154147 final String extName = "mobile: removeApp" ;
155148 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 );
161153 return requireNonNull (
162154 CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args )
163155 );
164156 } catch (UnsupportedCommandException | InvalidArgumentException e ) {
165157 // 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 ));
172161 //noinspection RedundantCast
173162 return requireNonNull (
174163 (Boolean ) CommandExecutionHelper .execute (
@@ -200,23 +189,17 @@ default void activateApp(String bundleId) {
200189 default void activateApp (String bundleId , @ Nullable BaseActivateApplicationOptions options ) {
201190 final String extName = "mobile: activateApp" ;
202191 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 );
208196 CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args );
209197 } catch (UnsupportedCommandException | InvalidArgumentException e ) {
210198 // 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 ));
220203 }
221204 }
222205
@@ -274,22 +257,18 @@ default boolean terminateApp(String bundleId) {
274257 default boolean terminateApp (String bundleId , @ Nullable BaseTerminateApplicationOptions options ) {
275258 final String extName = "mobile: terminateApp" ;
276259 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 );
282264 return requireNonNull (
283265 CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args )
284266 );
285267 } catch (UnsupportedCommandException | InvalidArgumentException e ) {
286268 // 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 ));
293272 //noinspection RedundantCast
294273 return requireNonNull (
295274 (Boolean ) CommandExecutionHelper .execute (
0 commit comments