Skip to content

Commit 02aa5d5

Browse files
valfirstMykola Mokhnach
authored and
Mykola Mokhnach
committed
Clean up (#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

+94
-117
lines changed

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
}

src/test/java/io/appium/java_client/android/AndroidDriverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public class AndroidDriverTest extends BaseAndroidTest {
258258

259259
}
260260

261-
@Test public void getPerformanceDataTest() throws Exception {
261+
@Test public void getPerformanceDataTest() {
262262
driver.startActivity(new Activity(APP_ID, ".ApiDemos"));
263263

264264
List<String> supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes();

src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.appium.java_client.appium.element.generation;
22

3-
import static org.junit.Assert.assertTrue;
3+
import static org.junit.Assert.assertEquals;
44

55
import io.appium.java_client.AppiumDriver;
66
import io.appium.java_client.service.local.AppiumServiceBuilder;
@@ -17,7 +17,7 @@ public class BaseElementGenerationTest {
1717
protected AppiumDriver<?> driver;
1818
protected final BiPredicate<By, Class<? extends WebElement>> commonPredicate = (by, aClass) -> {
1919
WebElement element = driver.findElement(by);
20-
assertTrue(element.getClass().equals(aClass));
20+
assertEquals(element.getClass(), aClass);
2121
return true;
2222
};
2323

src/test/java/io/appium/java_client/ios/IOSContextTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.hamcrest.core.StringContains.containsString;
2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.assertThat;
22-
import static org.junit.Assert.assertTrue;
2322

2423
import io.appium.java_client.NoSuchContextException;
2524
import org.junit.Test;
@@ -43,6 +42,6 @@ public class IOSContextTest extends BaseIOSWebViewTest {
4342

4443
@Test(expected = NoSuchContextException.class) public void testContextError() {
4544
driver.context("Planet of the Ape-ium");
46-
assertTrue(driver.getContext().equals("Planet of the Ape-ium"));
45+
assertEquals("Planet of the Ape-ium", driver.getContext());
4746
}
4847
}

src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static junit.framework.TestCase.assertNotNull;
2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertNotEquals;
24+
import static org.junit.Assert.assertTrue;
2425

2526
import io.appium.java_client.MobileElement;
2627
import io.appium.java_client.android.AndroidElement;
@@ -367,14 +368,14 @@ public class AndroidPageObjectTest extends BaseAndroidTest {
367368
}
368369

369370
@Test public void checkThatClassObjectMethodsDoNotInvokeTheSearching() {
370-
assertEquals(true, AndroidElement.class.isAssignableFrom(fakeElement.getClass()));
371-
assertEquals(false, AndroidElement.class.equals(fakeElement.getClass()));
372-
assertEquals(true, driver.equals(((WrapsDriver) fakeElement).getWrappedDriver()));
371+
assertTrue(AndroidElement.class.isAssignableFrom(fakeElement.getClass()));
372+
assertNotEquals(AndroidElement.class, fakeElement.getClass());
373+
assertEquals(driver, ((WrapsDriver) fakeElement).getWrappedDriver());
373374
}
374375

375376
@Test public void checkThatClassObjectMethodsDoNotInvokeTheSearchingOfElementLest() {
376-
assertEquals(true, List.class.isAssignableFrom(fakeElements.getClass()));
377-
assertEquals(false, ArrayList.class.equals(fakeElements.getClass()));
377+
assertTrue(List.class.isAssignableFrom(fakeElements.getClass()));
378+
assertNotEquals(ArrayList.class, fakeElements.getClass());
378379
}
379380

380381
@Test public void checkCached() {

src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE;
2020
import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver;
2121
import static java.time.Duration.ofSeconds;
22-
import static org.junit.Assert.assertEquals;
2322
import static org.junit.Assert.assertNotEquals;
23+
import static org.junit.Assert.assertNull;
2424

2525
import io.appium.java_client.android.AndroidDriver;
2626
import io.appium.java_client.pagefactory.AndroidFindBy;
@@ -67,10 +67,10 @@ public class DesktopBrowserCompatibilityTest {
6767
.toURI().toString());
6868
assertNotEquals(0, foundLinks.size());
6969
assertNotEquals(0, main.size());
70-
assertEquals(null, trap1);
71-
assertEquals(null, trap2);
70+
assertNull(trap1);
71+
assertNull(trap2);
7272
} finally {
7373
driver.quit();
7474
}
7575
}
76-
}
76+
}

src/test/java/io/appium/java_client/service/local/AppiumDriverLocalServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class AppiumDriverLocalServiceTest {
1313

1414
@Test
15-
public void canParseSlf4jLoggerContext() throws Exception {
15+
public void canParseSlf4jLoggerContext() {
1616
assertLoggerContext(INFO, "appium.service.androidbootstrap",
1717
"[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.");
1818
assertLoggerContext(INFO, "appium.service.adb",

src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void tearDown() throws Exception {
127127
@Test public void checkAbilityToStartDefaultService() {
128128
service = buildDefaultService();
129129
service.start();
130-
assertEquals(true, service.isRunning());
130+
assertTrue(service.isRunning());
131131
}
132132

133133
@Test public void checkAbilityToFindNodeDefinedInProperties() {

0 commit comments

Comments
 (0)