diff --git a/src/test/java/com/xceptance/neodymium/testclasses/multibrowser/BrowserWithoutAvailableEnvironment.java b/src/test/java/com/xceptance/neodymium/testclasses/multibrowser/BrowserWithoutAvailableEnvironment.java index 8207df8df..f79d6d9bb 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/multibrowser/BrowserWithoutAvailableEnvironment.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/multibrowser/BrowserWithoutAvailableEnvironment.java @@ -11,11 +11,12 @@ @RunWith(NeodymiumRunner.class) public class BrowserWithoutAvailableEnvironment { - - @Test(expected = IllegalArgumentException.class) + @Test @Browser("Galaxy_Note3_Emulation") public void testWithUnavailableEnvironment() { - Assert.assertEquals("Galaxy_Note3_Emulation", Neodymium.getBrowserProfileName()); + Assert.assertThrows(IllegalArgumentException.class, () -> { + Assert.assertEquals("Galaxy_Note3_Emulation", Neodymium.getBrowserProfileName()); + }); } } diff --git a/src/test/java/com/xceptance/neodymium/testclasses/proxy/RunWithProxy.java b/src/test/java/com/xceptance/neodymium/testclasses/proxy/RunWithProxy.java index f8d035496..887b6a30e 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/proxy/RunWithProxy.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/proxy/RunWithProxy.java @@ -3,6 +3,7 @@ import static com.codeborne.selenide.Condition.visible; import static com.codeborne.selenide.Selenide.$; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -16,11 +17,13 @@ public class RunWithProxy { // the test is expected to fail since we configured a not working proxy server - @Test(expected = ElementNotFound.class) + @Test public void testProxyConfiguration() { Selenide.open("https://www.xceptance.de"); - $("#page #navigation").shouldBe(visible); + Assert.assertThrows(ElementNotFound.class, () -> { + $("#page #navigation").shouldBe(visible); + }); } // the test is expected to run since we configured a bypass for "www.xceptance.com" diff --git a/src/test/java/com/xceptance/neodymium/testclasses/softassertion/UseSoftAssertions.java b/src/test/java/com/xceptance/neodymium/testclasses/softassertion/UseSoftAssertions.java index fd9736b7f..f2948e880 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/softassertion/UseSoftAssertions.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/softassertion/UseSoftAssertions.java @@ -24,7 +24,7 @@ public class UseSoftAssertions @Rule public SoftAsserts softAsserts = new SoftAsserts(); - @Test(expected = ElementNotFound.class) + @Test public void validateSoftAssertion() { Neodymium.softAssertions(true); @@ -35,9 +35,8 @@ public void validateSoftAssertion() $("#notFound2").should(exist); $("#masthead .search-toggle").click(); $("#notFound3").should(exist); - $("#notFound4").click(); - - // This should not be called since - throw new NullPointerException(); + Assert.assertThrows(ElementNotFound.class, () -> { + $("#notFound4").click(); + }); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/LocalizationInitializationErrorTest.java b/src/test/java/com/xceptance/neodymium/tests/LocalizationInitializationErrorTest.java index 555f24d32..c425031fd 100644 --- a/src/test/java/com/xceptance/neodymium/tests/LocalizationInitializationErrorTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/LocalizationInitializationErrorTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,9 +42,11 @@ public static void createLocalizationFile() throws IOException bw.close(); } - @Test(expected = RuntimeException.class) + @Test public void testAssertionErrorWhenKeyIsUnknown() { - Neodymium.localizedText("key1"); + Assert.assertThrows(RuntimeException.class, () -> { + Neodymium.localizedText("key1"); + }); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/LocalizationTest.java b/src/test/java/com/xceptance/neodymium/tests/LocalizationTest.java index 3a0a6c7d9..67e8ab808 100644 --- a/src/test/java/com/xceptance/neodymium/tests/LocalizationTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/LocalizationTest.java @@ -152,11 +152,13 @@ public void testEmptyKeyIsConvertedToEmptyString() Assert.assertEquals("", Neodymium.localizedText("key2")); } - @Test(expected = AssertionError.class) + @Test public void testAssertionErrorWhenKeyIsUnknown() { Neodymium.configuration().setProperty("neodymium.locale", "default"); - Neodymium.localizedText("key3"); + Assert.assertThrows(AssertionError.class, () -> { + Neodymium.localizedText("key3"); + }); } @Test diff --git a/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java b/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java index 5d98ceb99..7f3dfc61d 100644 --- a/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java +++ b/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java @@ -53,22 +53,25 @@ public void testMatchAttributeCondition() $("#search-container .search-field").should(SelenideAddons.matchAttribute("placeholder", "\\D+")); } - @Test(expected = ElementShould.class) + @Test public void testMatchAttributeConditionError() { Selenide.open("https://blog.xceptance.com/"); $("#masthead .search-toggle").click(); - $("#search-container .search-field").should(SelenideAddons.matchAttribute("placeholder", "\\d+")); + Assert.assertThrows(ElementShould.class, () -> { + $("#search-container .search-field").should(SelenideAddons.matchAttribute("placeholder", "\\d+")); + }); } - @Test(expected = ElementShould.class) + @Test public void testMatchAttributeConditionErrorMissingAttribute() { Selenide.open("https://blog.xceptance.com/"); $("#masthead .search-toggle").click(); - - $("#search-container .search-field").should(SelenideAddons.matchAttribute("foo", "bar")); + Assert.assertThrows(ElementShould.class, () -> { + $("#search-container .search-field").should(SelenideAddons.matchAttribute("foo", "bar")); + }); } @Test @@ -92,14 +95,15 @@ public void testMatchValueCondition() $("#content .search-field").should(SelenideAddons.matchValue("\\D+")); } - @Test(expected = ElementShould.class) + @Test public void testMatchValueConditionError() { Selenide.open("https://blog.xceptance.com/"); $("#masthead .search-toggle").click(); $("#search-container .search-field").val("searchphrase").submit(); - - $("#content .search-field").should(SelenideAddons.matchValue("\\d+")); + Assert.assertThrows(ElementShould.class, () -> { + $("#content .search-field").should(SelenideAddons.matchValue("\\d+")); + }); } @Test() @@ -111,12 +115,14 @@ public void testWrapAssertion() }); } - @Test(expected = UIAssertionError.class) + @Test public void testWrapAssertionError() { Selenide.open("https://blog.xceptance.com/"); - SelenideAddons.wrapAssertionError(() -> { - Assert.assertEquals("MyPageTitle", Selenide.title()); + Assert.assertThrows(UIAssertionError.class, () -> { + SelenideAddons.wrapAssertionError(() -> { + Assert.assertEquals("MyPageTitle", Selenide.title()); + }); }); }