Skip to content

Commit c143f1a

Browse files
authored
test: Clean up unit tests asserting thrown exceptions (#1741)
1 parent f9cd5bb commit c143f1a

File tree

6 files changed

+11
-31
lines changed

6 files changed

+11
-31
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ public class AndroidContextTest extends BaseAndroidTest {
4848
}
4949

5050
@Test public void testContextError() {
51-
assertThrows(NoSuchContextException.class,
52-
() -> {
53-
driver.context("Planet of the Ape-ium");
54-
assertEquals("Planet of the Ape-ium", driver.getContext());
55-
});
51+
assertThrows(NoSuchContextException.class, () -> driver.context("Planet of the Ape-ium"));
5652
}
5753

5854
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import static org.hamcrest.core.Is.is;
77
import static org.hamcrest.core.StringContains.containsString;
88
import static org.junit.jupiter.api.Assertions.assertThrows;
9-
import static org.junit.jupiter.api.Assertions.assertTrue;
109

1110
import io.appium.java_client.functions.AppiumFunction;
1211
import io.appium.java_client.functions.ExpectedCondition;
@@ -132,15 +131,14 @@ public void complexWaitingTestWithPreCondition() {
132131
public void nullPointerExceptionSafetyTestWithPrecondition() {
133132
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
134133
.withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
135-
assertThrows(TimeoutException.class,
136-
() -> assertTrue(wait.until(searchingFunction.compose(contextFunction)).size() > 0));
134+
assertThrows(TimeoutException.class, () -> wait.until(searchingFunction.compose(contextFunction)));
137135
}
138136

139137
@Test
140138
public void nullPointerExceptionSafetyTestWithPostConditions() {
141139
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
142140
.withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
143141
assertThrows(TimeoutException.class,
144-
() -> assertTrue(wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)).size() > 0));
142+
() -> wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)));
145143
}
146144
}

src/test/java/io/appium/java_client/internal/ConfigTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ public void verifyGettingExistingValue() {
2020

2121
@Test
2222
public void verifyGettingNonExistingValue() {
23-
assertThrows(IllegalArgumentException.class,
24-
() -> assertThat(Config.main().getValue(MISSING_KEY, String.class).length(), greaterThan(0)));
23+
assertThrows(IllegalArgumentException.class, () -> Config.main().getValue(MISSING_KEY, String.class));
2524
}
2625

2726
@Test
2827
public void verifyGettingExistingValueWithWrongClass() {
29-
assertThrows(ClassCastException.class,
30-
() -> assertThat(Config.main().getValue(EXISTING_KEY, Integer.class), greaterThan(0)));
28+
assertThrows(ClassCastException.class, () -> Config.main().getValue(EXISTING_KEY, Integer.class));
3129
}
3230

3331
@Test

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ public class IOSContextTest extends BaseIOSWebViewTest {
4242
}
4343

4444
@Test public void testContextError() {
45-
assertThrows(NoSuchContextException.class,
46-
() -> {
47-
driver.context("Planet of the Ape-ium");
48-
assertEquals("Planet of the Ape-ium", driver.getContext());
49-
});
45+
assertThrows(NoSuchContextException.class, () -> driver.context("Planet of the Ape-ium"));
5046
}
5147
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ public class AndroidPageObjectTest extends BaseAndroidTest {
326326

327327
@Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() {
328328
assertThrows(NoSuchElementException.class,
329-
() -> assertNotNull(
330-
elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text")));
329+
() -> elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text"));
331330
}
332331

333332
@Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindByList() {
@@ -351,8 +350,7 @@ public class AndroidPageObjectTest extends BaseAndroidTest {
351350

352351
@Test
353352
public void checkThatElementSearchingThrowsExpectedExceptionIfChainedLocatorIsInvalid() {
354-
assertThrows(NoSuchElementException.class,
355-
() -> assertNotNull(elementFoundByInvalidChainedSelector.getAttribute("text")));
353+
assertThrows(NoSuchElementException.class, () -> elementFoundByInvalidChainedSelector.getAttribute("text"));
356354
}
357355

358356
@Test public void checkThatListSearchingWorksIfChainedLocatorIsInvalid() {

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,22 +339,16 @@ public void checkAbilityToStartServiceUsingValidBasePathWithSinglePathParams() {
339339

340340
@Test
341341
public void checkAbilityToValidateBasePathForEmptyBasePath() {
342-
assertThrows(IllegalArgumentException.class, () -> {
343-
new AppiumServiceBuilder().withArgument(BASEPATH, "").build();
344-
});
342+
assertThrows(IllegalArgumentException.class, () -> new AppiumServiceBuilder().withArgument(BASEPATH, ""));
345343
}
346344

347345
@Test
348346
public void checkAbilityToValidateBasePathForBlankBasePath() {
349-
assertThrows(IllegalArgumentException.class, () -> {
350-
new AppiumServiceBuilder().withArgument(BASEPATH, " ").build();
351-
});
347+
assertThrows(IllegalArgumentException.class, () -> new AppiumServiceBuilder().withArgument(BASEPATH, " "));
352348
}
353349

354350
@Test
355351
public void checkAbilityToValidateBasePathForNullBasePath() {
356-
assertThrows(NullPointerException.class, () -> {
357-
new AppiumServiceBuilder().withArgument(BASEPATH, null).build();
358-
});
352+
assertThrows(NullPointerException.class, () -> new AppiumServiceBuilder().withArgument(BASEPATH, null));
359353
}
360354
}

0 commit comments

Comments
 (0)