Skip to content

Commit

Permalink
Merge pull request #129 from Xceptance/#128-replace-expected-with-assert
Browse files Browse the repository at this point in the history
#128 replace expected with assert
  • Loading branch information
occupant23 authored Jul 27, 2020
2 parents cd53140 + 8cb269e commit f0c4a74
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class UseSoftAssertions
@Rule
public SoftAsserts softAsserts = new SoftAsserts();

@Test(expected = ElementNotFound.class)
@Test
public void validateSoftAssertion()
{
Neodymium.softAssertions(true);
Expand All @@ -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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 17 additions & 11 deletions src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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());
});
});
}

Expand Down

0 comments on commit f0c4a74

Please sign in to comment.