Skip to content

Commit ce9c5dc

Browse files
codecy issues were got fixed
1 parent e68fd3f commit ce9c5dc

10 files changed

Lines changed: 98 additions & 110 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.appium.java_client.remote.IOSMobileCapabilityType;
44
import io.appium.java_client.remote.MobileCapabilityType;
55
import io.appium.java_client.service.local.AppiumDriverLocalService;
6+
import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;
67
import org.junit.BeforeClass;
78
import org.openqa.selenium.remote.DesiredCapabilities;
89

@@ -16,7 +17,7 @@ public static void beforeClass() throws Exception {
1617
service.start();
1718

1819
if (service == null || !service.isRunning()) {
19-
throw new RuntimeException("An appium server node is not started!");
20+
throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!");
2021
}
2122

2223
File appDir = new File("src/test/java/io/appium/java_client");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.appium.java_client.remote.IOSMobileCapabilityType;
2020
import io.appium.java_client.remote.MobileCapabilityType;
2121
import io.appium.java_client.service.local.AppiumDriverLocalService;
22+
import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;
2223
import org.junit.BeforeClass;
2324
import org.openqa.selenium.remote.DesiredCapabilities;
2425

@@ -31,7 +32,7 @@ public class BaseIOSWebViewTest extends BaseIOSTest {
3132
service.start();
3233

3334
if (service == null || !service.isRunning()) {
34-
throw new RuntimeException("An appium server node is not started!");
35+
throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!");
3536
}
3637

3738
File appDir = new File("src/test/java/io/appium/java_client");

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.appium.java_client.ios;
1818

1919
import static junit.framework.TestCase.assertFalse;
20+
import static org.junit.Assert.assertTrue;
2021
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
2122

2223
import io.appium.java_client.MobileBy;
@@ -26,24 +27,34 @@
2627
import org.junit.runners.MethodSorters;
2728
import org.openqa.selenium.support.ui.WebDriverWait;
2829

30+
import java.util.function.Supplier;
31+
2932
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3033
public class IOSAlertTest extends AppIOSTest {
3134

32-
WebDriverWait waiting = new WebDriverWait(driver, 10000);
33-
static final String iOSAutomationText = ".elements().withName(\"show alert\")";
35+
private WebDriverWait waiting = new WebDriverWait(driver, 10000);
36+
private static final String iOSAutomationText = ".elements().withName(\"show alert\")";
3437

3538
@Test public void acceptAlertTest() {
36-
driver.findElement(MobileBy
37-
.IosUIAutomation(iOSAutomationText)).click();
38-
waiting.until(alertIsPresent());
39-
driver.switchTo().alert().accept();
39+
Supplier<Boolean> acceptAlert = () -> {
40+
driver.findElement(MobileBy
41+
.IosUIAutomation(iOSAutomationText)).click();
42+
waiting.until(alertIsPresent());
43+
driver.switchTo().alert().accept();
44+
return true;
45+
};
46+
assertTrue(acceptAlert.get());
4047
}
4148

4249
@Test public void dismissAlertTest() {
43-
driver.findElement(MobileBy
44-
.IosUIAutomation(iOSAutomationText)).click();
45-
waiting.until(alertIsPresent());
46-
driver.switchTo().alert().dismiss();
50+
Supplier<Boolean> dismissAlert = () -> {
51+
driver.findElement(MobileBy
52+
.IosUIAutomation(iOSAutomationText)).click();
53+
waiting.until(alertIsPresent());
54+
driver.switchTo().alert().dismiss();
55+
return true;
56+
};
57+
assertTrue(dismissAlert.get());
4758
}
4859

4960
@Test public void getAlertTextTest() {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.openqa.selenium.ScreenOrientation;
2828
import org.openqa.selenium.html5.Location;
2929

30+
import java.util.function.Supplier;
31+
3032
public class IOSDriverTest extends AppIOSTest {
3133

3234
//TODO There is no ability to check this function usibg simulators.
@@ -59,7 +61,11 @@ public void getDeviceTimeTest() {
5961
}
6062

6163
@Test public void lockTest() {
62-
driver.lockDevice(20);
64+
Supplier<Boolean> lock = () -> {
65+
driver.lockDevice(20);
66+
return true;
67+
};
68+
assertTrue(lock.get());
6369
}
6470

6571
@Test public void pullFileTest() {

src/test/java/io/appium/java_client/localserver/ThreadSafetyTest.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
package io.appium.java_client.localserver;
22

3+
import static org.junit.Assert.assertFalse;
34
import static org.junit.Assert.assertTrue;
45

56
import io.appium.java_client.service.local.AppiumDriverLocalService;
67
import org.junit.Test;
78

89
public class ThreadSafetyTest {
910

10-
final AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();
11-
final Action run = new Action() {
11+
private final AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();
12+
private final Action run = new Action() {
1213
@Override Object perform() {
1314
service.start();
1415
return "OK";
1516
}
1617
};
17-
final Action run2 = run.clone();
18-
final Action isRunning = new Action() {
18+
private final Action run2 = run.clone();
19+
private final Action isRunning = new Action() {
1920
@Override Object perform() {
2021
return service.isRunning();
2122
}
2223
};
23-
final Action isRunning2 = isRunning.clone();
24-
final Action stop = new Action() {
24+
private final Action isRunning2 = isRunning.clone();
25+
private final Action stop = new Action() {
2526
@Override Object perform() {
2627
service.stop();
2728
return "OK";
2829
}
2930
};
30-
final Action stop2 = stop.clone();
31+
private final Action stop2 = stop.clone();
3132

3233
@Test public void whenFewTreadsDoTheSameWork() throws Throwable {
3334

@@ -65,8 +66,8 @@ public class ThreadSafetyTest {
6566
throw runTestThread2.throwable;
6667
}
6768

68-
assertTrue(runTestThread.result.equals("OK"));
69-
assertTrue(runTestThread2.result.equals("OK"));
69+
assertTrue("OK".equals(runTestThread.result));
70+
assertTrue("OK".equals(runTestThread2.result));
7071
assertTrue(service.isRunning());
7172

7273
isRunningThread.start();
@@ -102,9 +103,9 @@ public class ThreadSafetyTest {
102103
throw stopTestThread2.throwable;
103104
}
104105

105-
assertTrue(stopTestThread.result.equals("OK"));
106-
assertTrue(stopTestThread2.result.equals("OK"));
107-
assertTrue(!service.isRunning());
106+
assertTrue("OK".equals(stopTestThread.result));
107+
assertTrue("OK".equals(stopTestThread2.result));
108+
assertFalse(service.isRunning());
108109
} finally {
109110
if (service.isRunning()) {
110111
service.stop();
@@ -155,12 +156,10 @@ public class ThreadSafetyTest {
155156
throw stopTestThread.throwable;
156157
}
157158

158-
assertTrue(
159-
runTestThread.result.equals("OK")); //the service had been started firstly (see (1))
160-
assertTrue(isRunningTestThread.result.equals(true)); //it was running (see (2))
161-
assertTrue(stopTestThread.result
162-
.equals("OK")); //and then the test tried to shut down it (see (3))
163-
assertTrue(!service.isRunning());
159+
assertTrue("OK".equals(runTestThread.result)); //the service had been started firstly (see (1))
160+
assertTrue(Boolean.TRUE.equals(isRunningTestThread.result)); //it was running (see (2))
161+
assertTrue("OK".equals(stopTestThread.result)); //and then the test tried to shut down it (see (3))
162+
assertFalse(service.isRunning());
164163

165164
isRunningThread2.start(); // (1)
166165
Thread.sleep(10);
@@ -184,11 +183,11 @@ public class ThreadSafetyTest {
184183
throw stopTestThread.throwable;
185184
}
186185

187-
assertTrue(isRunningTestThread2.result
188-
.equals(false)); //the service wasn'throwable being running (see (1))
189-
assertTrue(stopTestThread2.result
190-
.equals("OK")); //the service had not been started firstly (see (2)), it is ok
191-
assertTrue(runTestThread2.result.equals("OK")); //and then it was started (see (3))
186+
//the service wasn'throwable being running (see (1))
187+
assertTrue(Boolean.FALSE.equals(isRunningTestThread2.result));
188+
//the service had not been started firstly (see (2)), it is ok
189+
assertTrue("OK".equals(stopTestThread2.result));
190+
assertTrue("OK".equals(runTestThread2.result)); //and then it was started (see (3))
192191
assertTrue(service.isRunning());
193192
} finally {
194193
if (service.isRunning()) {

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,8 @@ public class AndroidPageObjectTest extends BaseAndroidTest {
201201
assertEquals(0, iosTextViews.size());
202202
}
203203

204-
@Test public void checkThatElementWasNotFoundByIOSUIAutomator() {
205-
NoSuchElementException nsee = null;
206-
try {
207-
iosTextView.getAttribute("text");
208-
} catch (Exception e) {
209-
nsee = (NoSuchElementException) e;
210-
}
211-
assertNotNull(nsee);
204+
@Test(expected = NoSuchElementException.class) public void checkThatElementWasNotFoundByIOSUIAutomator() {
205+
assertNotNull(iosTextView.getAttribute("text"));
212206
}
213207

214208
@Test public void androidOrIOSFindByElementsTest() {
@@ -263,14 +257,8 @@ public class AndroidPageObjectTest extends BaseAndroidTest {
263257
assertEquals(0, iosChainTextViews.size());
264258
}
265259

266-
@Test public void checkThatElementWasNotFoundByIOSUIAutomatorChain() {
267-
NoSuchElementException nsee = null;
268-
try {
269-
iosChainTextView.getAttribute("text");
270-
} catch (Exception e) {
271-
nsee = (NoSuchElementException) e;
272-
}
273-
assertNotNull(nsee);
260+
@Test(expected = NoSuchElementException.class) public void checkThatElementWasNotFoundByIOSUIAutomatorChain() {
261+
assertNotNull(iosChainTextView.getAttribute("text"));
274262
}
275263

276264
@Test public void androidOrIOSFindByElementsTestChainSearches() {
@@ -301,14 +289,9 @@ public class AndroidPageObjectTest extends BaseAndroidTest {
301289
assertNotEquals(null, textAndroidId.getAttribute("text"));
302290
}
303291

304-
@Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() {
305-
try {
306-
assertNotEquals(null,
292+
@Test(expected = NoSuchElementException.class) public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() {
293+
assertNotNull(
307294
elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text"));
308-
} catch (NoSuchElementException ignored) {
309-
return;
310-
}
311-
throw new RuntimeException(NoSuchElementException.class.getName() + " has been expected.");
312295
}
313296

314297
@Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindByList() {

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
2626
import io.appium.java_client.pagefactory.HowToUseLocators;
2727
import io.appium.java_client.pagefactory.iOSFindBy;
28+
import org.junit.BeforeClass;
2829
import org.junit.Test;
2930
import org.openqa.selenium.Platform;
3031
import org.openqa.selenium.WebDriver;
@@ -42,7 +43,7 @@
4243
public class DesktopBrowserCompatibilityTest {
4344

4445

45-
private final Platform current = Platform.getCurrent();
46+
private static final Platform current = Platform.getCurrent();
4647
@HowToUseLocators(iOSAutomation = ALL_POSSIBLE)
4748
@AndroidFindBy(className = "someClass")
4849
@iOSFindBy(xpath = "//selector[1]") @iOSFindBy(xpath = "//someTag")
@@ -55,7 +56,7 @@ public class DesktopBrowserCompatibilityTest {
5556
/**
5657
* The starting.
5758
*/
58-
public void setUp() {
59+
@BeforeClass public static void beforeClass() {
5960
if (current.is(Platform.WINDOWS)) {
6061
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
6162
"src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe");
@@ -65,14 +66,14 @@ public void setUp() {
6566
}
6667
}
6768

68-
private void test() {
69+
@Test public void chromeTest() {
6970
WebDriver driver = new ChromeDriver();
7071
try {
7172
PageFactory
72-
.initElements(new AppiumFieldDecorator(driver, 15, TimeUnit.SECONDS),
73-
this);
73+
.initElements(new AppiumFieldDecorator(driver, 15, TimeUnit.SECONDS),
74+
this);
7475
driver.get(new File("src/test/java/io/appium/java_client/hello appium - saved page.htm")
75-
.toURI().toString());
76+
.toURI().toString());
7677
assertNotEquals(0, foundLinks.size());
7778
assertNotEquals(0, main.size());
7879
assertEquals(null, trap1);
@@ -81,9 +82,4 @@ private void test() {
8182
driver.quit();
8283
}
8384
}
84-
85-
@Test public void chromeTest() {
86-
setUp();
87-
test();
88-
}
8985
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.appium.java_client.pagefactory_tests;
22

3+
import static org.junit.Assert.assertTrue;
34

45
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
56
import org.junit.Test;
@@ -10,6 +11,7 @@
1011

1112
import java.util.List;
1213
import java.util.Set;
14+
import java.util.function.Supplier;
1315

1416
public class GenericTest {
1517

@@ -92,8 +94,12 @@ public Options manage() {
9294

9395
@Test
9496
public void genericTestCse() {
95-
PageFactory
96-
.initElements(new AppiumFieldDecorator(new MockWebDriver()),
97-
new TempGenericPage<>());
97+
Supplier<Boolean> result = () -> {
98+
PageFactory
99+
.initElements(new AppiumFieldDecorator(new MockWebDriver()),
100+
new TempGenericPage<>());
101+
return true;
102+
};
103+
assertTrue(result.get());
98104
}
99105
}

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

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,8 @@ public class IOSPageFactoryTest extends AppIOSTest {
166166
assertEquals(0, androidUIAutomatorViews.size());
167167
}
168168

169-
@Test public void checkThatElementWasNotFoundByAndroidUIAutomator() {
170-
NoSuchElementException nsee = null;
171-
try {
172-
androidUIAutomatorView.getText();
173-
} catch (Exception e) {
174-
nsee = (NoSuchElementException) e;
175-
}
176-
assertNotNull(nsee);
169+
@Test(expected = NoSuchElementException.class) public void checkThatElementWasNotFoundByAndroidUIAutomator() {
170+
assertNotNull(androidUIAutomatorView.getText());
177171
}
178172

179173
@Test public void androidOriOSFindByElementsTest() {
@@ -220,14 +214,8 @@ public class IOSPageFactoryTest extends AppIOSTest {
220214
assertEquals(0, chainElementViews.size());
221215
}
222216

223-
@Test public void checkThatElementWasNotFoundByAndroidUIAutomatorChain() {
224-
NoSuchElementException nsee = null;
225-
try {
226-
chainElementView.getText();
227-
} catch (Exception e) {
228-
nsee = (NoSuchElementException) e;
229-
}
230-
assertNotNull(nsee);
217+
@Test(expected = NoSuchElementException.class) public void checkThatElementWasNotFoundByAndroidUIAutomatorChain() {
218+
assertNotNull(chainElementView.getText());
231219
}
232220

233221
@Test public void isIOSElementTest() {
@@ -246,15 +234,9 @@ public class IOSPageFactoryTest extends AppIOSTest {
246234
assertNotEquals(null, findAllElement.getText());
247235
}
248236

249-
@Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() {
250-
try {
251-
assertNotEquals(null,
252-
elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy
237+
@Test(expected = NoSuchElementException.class) public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() {
238+
assertNotNull(elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy
253239
.getAttribute("text"));
254-
} catch (NoSuchElementException ignored) {
255-
return;
256-
}
257-
throw new RuntimeException(NoSuchElementException.class.getName() + " has been expected.");
258240
}
259241

260242
@Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindByList() {

0 commit comments

Comments
 (0)