Skip to content

Commit 02aa5d5

Browse files
valfirstMykola Mokhnach
authored andcommitted
Clean up (appium#1028)
* Remove redundant 'throws' clauses * Simplify assertions in unit tests * Replace 'Collection.addAll()' with parametrized constructor call * Remove redundant array creation for calling varargs method * Remove redundant type arguments * Use `isEmpty` to check for empty string
1 parent 8d3f254 commit 02aa5d5

19 files changed

Lines changed: 94 additions & 117 deletions

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
445445
* {@link java.util.Map} command arguments.
446446
*/
447447
public static Map.Entry<String, Map<String, ?>> unlockDeviceCommand() {
448-
return new AbstractMap.SimpleEntry<>(UNLOCK, ImmutableMap.<String, Object>of());
448+
return new AbstractMap.SimpleEntry<>(UNLOCK, ImmutableMap.of());
449449
}
450450

451451
/**
@@ -456,11 +456,11 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
456456
* {@link java.util.Map} command arguments.
457457
*/
458458
public static Map.Entry<String, Map<String, ?>> getIsDeviceLockedCommand() {
459-
return new AbstractMap.SimpleEntry<>(IS_LOCKED, ImmutableMap.<String, Object>of());
459+
return new AbstractMap.SimpleEntry<>(IS_LOCKED, ImmutableMap.of());
460460
}
461461

462462
public static Map.Entry<String, Map<String, ?>> getSettingsCommand() {
463-
return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.<String, Object>of());
463+
return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.of());
464464
}
465465

466466
public static Map.Entry<String, Map<String, ?>> setSettingsCommand(Setting setting, Object value) {
@@ -522,7 +522,6 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
522522
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
523523
*/
524524
public static Map.Entry<String, Map<String, ?>> isKeyboardShownCommand() {
525-
return new AbstractMap.SimpleEntry<>(
526-
IS_KEYBOARD_SHOWN, ImmutableMap.<String, Object>of());
525+
return new AbstractMap.SimpleEntry<>(IS_KEYBOARD_SHOWN, ImmutableMap.of());
527526
}
528527
}

‎src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java‎

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
4040
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
4141
*/
4242
public static Map.Entry<String, Map<String, ?>> currentActivityCommand() {
43-
return new AbstractMap.SimpleEntry<>(
44-
CURRENT_ACTIVITY, ImmutableMap.<String, Object>of());
43+
return new AbstractMap.SimpleEntry<>(CURRENT_ACTIVITY, ImmutableMap.of());
4544
}
4645

4746
/**
@@ -50,8 +49,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
5049
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
5150
*/
5251
public static Map.Entry<String, Map<String, ?>> currentPackageCommand() {
53-
return new AbstractMap.SimpleEntry<>(
54-
GET_CURRENT_PACKAGE, ImmutableMap.<String, Object>of());
52+
return new AbstractMap.SimpleEntry<>(GET_CURRENT_PACKAGE, ImmutableMap.of());
5553
}
5654

5755
/**
@@ -77,8 +75,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
7775
*
7876
*/
7977
public static Map.Entry<String, Map<String, ?>> getSupportedPerformanceDataTypesCommand() {
80-
return new AbstractMap.SimpleEntry<>(
81-
GET_SUPPORTED_PERFORMANCE_DATA_TYPES, ImmutableMap.<String, Object>of());
78+
return new AbstractMap.SimpleEntry<>(GET_SUPPORTED_PERFORMANCE_DATA_TYPES, ImmutableMap.of());
8279
}
8380

8481
/**
@@ -108,10 +105,9 @@ public class AndroidMobileCommandHelper extends MobileCommand {
108105
* [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
109106
* [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
110107
* in case of cpu info : [[user, kernel], [0.9, 1.3]]
111-
* @throws Exception if the performance data type is not supported, thows Error
112108
*/
113109
public static Map.Entry<String, Map<String, ?>> getPerformanceDataCommand(
114-
String packageName, String dataType, int dataReadTimeout) throws Exception {
110+
String packageName, String dataType, int dataReadTimeout) {
115111
String[] parameters = new String[] {"packageName", "dataType", "dataReadTimeout"};
116112
Object[] values = new Object[] {packageName, dataType, dataReadTimeout};
117113
return new AbstractMap.SimpleEntry<>(
@@ -126,8 +122,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
126122
* {@link Map} command arguments.
127123
*/
128124
public static Map.Entry<String, Map<String, ?>> getDisplayDensityCommand() {
129-
return new AbstractMap.SimpleEntry<>(
130-
GET_DISPLAY_DENSITY, ImmutableMap.<String, Object>of());
125+
return new AbstractMap.SimpleEntry<>(GET_DISPLAY_DENSITY, ImmutableMap.of());
131126
}
132127

133128
/**
@@ -137,8 +132,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
137132
* {@link Map} command arguments.
138133
*/
139134
public static Map.Entry<String, Map<String, ?>> getNetworkConnectionCommand() {
140-
return new AbstractMap.SimpleEntry<>(
141-
GET_NETWORK_CONNECTION, ImmutableMap.<String, Object>of());
135+
return new AbstractMap.SimpleEntry<>(GET_NETWORK_CONNECTION, ImmutableMap.of());
142136
}
143137

144138
/**
@@ -148,8 +142,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
148142
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
149143
*/
150144
public static Map.Entry<String, Map<String, ?>> getSystemBarsCommand() {
151-
return new AbstractMap.SimpleEntry<>(
152-
GET_SYSTEM_BARS, ImmutableMap.<String, Object>of());
145+
return new AbstractMap.SimpleEntry<>(GET_SYSTEM_BARS, ImmutableMap.of());
153146
}
154147

155148
/**
@@ -159,8 +152,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
159152
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
160153
*/
161154
public static Map.Entry<String, Map<String, ?>> isLockedCommand() {
162-
return new AbstractMap.SimpleEntry<>(
163-
IS_LOCKED, ImmutableMap.<String, Object>of());
155+
return new AbstractMap.SimpleEntry<>(IS_LOCKED, ImmutableMap.of());
164156
}
165157

166158
/**
@@ -180,8 +172,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
180172
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
181173
*/
182174
public static Map.Entry<String, Map<String, ?>> openNotificationsCommand() {
183-
return new AbstractMap.SimpleEntry<>(
184-
OPEN_NOTIFICATIONS, ImmutableMap.<String, Object>of());
175+
return new AbstractMap.SimpleEntry<>(OPEN_NOTIFICATIONS, ImmutableMap.of());
185176
}
186177

187178
/**
@@ -250,7 +241,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
250241
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
251242
*/
252243
public static Map.Entry<String, Map<String, ?>> toggleLocationServicesCommand() {
253-
return new AbstractMap.SimpleEntry<>(TOGGLE_LOCATION_SERVICES, ImmutableMap.<String, Object>of());
244+
return new AbstractMap.SimpleEntry<>(TOGGLE_LOCATION_SERVICES, ImmutableMap.of());
254245
}
255246

256247
/**
@@ -259,7 +250,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
259250
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
260251
*/
261252
public static Map.Entry<String, Map<String, ?>> unlockCommand() {
262-
return new AbstractMap.SimpleEntry<>(UNLOCK, ImmutableMap.<String, Object>of());
253+
return new AbstractMap.SimpleEntry<>(UNLOCK, ImmutableMap.of());
263254
}
264255

265256

@@ -392,7 +383,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
392383
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
393384
*/
394385
public static Map.Entry<String, Map<String, ?>> toggleWifiCommand() {
395-
return new AbstractMap.SimpleEntry<>(TOGGLE_WIFI, ImmutableMap.<String, Object>of());
386+
return new AbstractMap.SimpleEntry<>(TOGGLE_WIFI, ImmutableMap.of());
396387
}
397388

398389
/**
@@ -401,7 +392,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
401392
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
402393
*/
403394
public static Map.Entry<String, Map<String, ?>> toggleAirplaneCommand() {
404-
return new AbstractMap.SimpleEntry<>(TOGGLE_AIRPLANE_MODE, ImmutableMap.<String, Object>of());
395+
return new AbstractMap.SimpleEntry<>(TOGGLE_AIRPLANE_MODE, ImmutableMap.of());
405396
}
406397

407398
/**
@@ -410,6 +401,6 @@ public class AndroidMobileCommandHelper extends MobileCommand {
410401
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
411402
*/
412403
public static Map.Entry<String, Map<String, ?>> toggleDataCommand() {
413-
return new AbstractMap.SimpleEntry<>(TOGGLE_DATA, ImmutableMap.<String, Object>of());
404+
return new AbstractMap.SimpleEntry<>(TOGGLE_DATA, ImmutableMap.of());
414405
}
415406
}

‎src/main/java/io/appium/java_client/android/HasSupportedPerformanceDataType.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ default List<String> getSupportedPerformanceDataTypes() {
4848
* [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
4949
* [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
5050
* in case of cpu info : [[user, kernel], [0.9, 1.3]]
51-
* @throws Exception if the performance data type is not supported, thows Error
5251
*/
53-
default List<List<Object>> getPerformanceData(String packageName, String dataType, int dataReadTimeout)
54-
throws Exception {
52+
default List<List<Object>> getPerformanceData(String packageName, String dataType, int dataReadTimeout) {
5553
return CommandExecutionHelper.execute(this,
5654
getPerformanceDataCommand(packageName, dataType, dataReadTimeout));
5755
}

‎src/main/java/io/appium/java_client/events/DefaultAspect.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private Object transformToListenable(Object toBeTransformed) {
165165
return result;
166166
}
167167

168-
private List<Object> returnProxyList(List<Object> originalList) throws Exception {
168+
private List<Object> returnProxyList(List<Object> originalList) {
169169
try {
170170
List<Object> proxyList = new ArrayList<>();
171171
for (Object o : originalList) {

‎src/main/java/io/appium/java_client/ios/IOSMobileCommandHelper.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public class IOSMobileCommandHelper extends MobileCommand {
3131
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
3232
*/
3333
public static Map.Entry<String, Map<String, ?>> shakeCommand() {
34-
return new AbstractMap.SimpleEntry<>(
35-
SHAKE, ImmutableMap.<String, Object>of());
34+
return new AbstractMap.SimpleEntry<>(SHAKE, ImmutableMap.of());
3635
}
3736

3837
/**

‎src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ private static String getFilledValue(Annotation mobileBy) {
9696
}
9797

9898
try {
99-
String strategyParameter = value.invoke(mobileBy, new Object[] {}).toString();
100-
if (!"".equals(strategyParameter)) {
99+
String strategyParameter = value.invoke(mobileBy).toString();
100+
if (!strategyParameter.isEmpty()) {
101101
return value.getName();
102102
}
103103
} catch (IllegalAccessException

‎src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private static String getValue(Annotation annotation, Strategies strategy) {
127127
try {
128128
Method m = annotation.getClass()
129129
.getMethod(strategy.valueName, AppiumByBuilder.DEFAULT_ANNOTATION_METHOD_ARGUMENTS);
130-
return m.invoke(annotation, new Object[] {}).toString();
130+
return m.invoke(annotation).toString();
131131
} catch (NoSuchMethodException
132132
| SecurityException
133133
| IllegalAccessException

‎src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,7 @@ public Object setValue(Object value) {
497497
}
498498

499499
private Map<String, Object> applyTransforms(Map<String, Object> caps) {
500-
Queue<Map.Entry<String, Object>> toExamine = new LinkedList<>();
501-
toExamine.addAll(caps.entrySet());
500+
Queue<Map.Entry<String, Object>> toExamine = new LinkedList<>(caps.entrySet());
502501
Set<String> seenKeys = new HashSet<>();
503502
Map<String, Object> toReturn = new TreeMap<>();
504503

‎src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public void addLogMessageConsumer(Consumer<String> consumer) {
349349
StringBuilder lineBuilder = new StringBuilder();
350350

351351
@Override
352-
public void write(int chr) throws IOException {
352+
public void write(int chr) {
353353
try {
354354
lineBuilder.append((char) chr);
355355
Matcher matcher = LOG_MESSAGE_PATTERN.matcher(lineBuilder.toString());

‎src/test/java/io/appium/java_client/android/AndroidContextTest.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package io.appium.java_client.android;
1818

1919
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
2120

2221
import io.appium.java_client.NoSuchContextException;
2322
import org.junit.BeforeClass;
@@ -49,7 +48,7 @@ public class AndroidContextTest extends BaseAndroidTest {
4948

5049
@Test(expected = NoSuchContextException.class) public void testContextError() {
5150
driver.context("Planet of the Ape-ium");
52-
assertTrue(driver.getContext().equals("Planet of the Ape-ium"));
51+
assertEquals("Planet of the Ape-ium", driver.getContext());
5352
}
5453

5554
}

0 commit comments

Comments
 (0)