Skip to content

Commit f4e23dd

Browse files
committed
[java] Minor unit test improvements
1 parent f07a95c commit f4e23dd

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

java/client/test/org/openqa/selenium/ByTest.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import static org.assertj.core.api.Assertions.assertThat;
2929
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
30-
import static org.assertj.core.api.Assertions.fail;
30+
import static org.assertj.core.api.Assertions.assertThatNoException;
3131
import static org.mockito.Mockito.mock;
3232
import static org.mockito.Mockito.verify;
3333
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -46,7 +46,7 @@ public class ByTest {
4646

4747
@Test
4848
public void shouldUseFindsByNameToLocateElementsByName() {
49-
final AllDriver driver = mock(AllDriver.class);
49+
final SearchContext driver = mock(SearchContext.class);
5050

5151
By.cssSelector("cheese").findElement(driver);
5252
By.cssSelector("peas").findElements(driver);
@@ -58,7 +58,7 @@ public void shouldUseFindsByNameToLocateElementsByName() {
5858

5959
@Test
6060
public void shouldUseXpathLocateElementsByXpath() {
61-
AllDriver driver = mock(AllDriver.class);
61+
SearchContext driver = mock(SearchContext.class);
6262

6363
By.xpath(".//*[@name = 'cheese']").findElement(driver);
6464
By.xpath(".//*[@name = 'peas']").findElements(driver);
@@ -70,7 +70,7 @@ public void shouldUseXpathLocateElementsByXpath() {
7070

7171
@Test
7272
public void searchesByTagNameIfSupported() {
73-
AllDriver context = mock(AllDriver.class);
73+
SearchContext context = mock(SearchContext.class);
7474

7575
By.tagName("foo").findElement(context);
7676
By.tagName("bar").findElements(context);
@@ -82,14 +82,14 @@ public void searchesByTagNameIfSupported() {
8282

8383
@Test
8484
public void innerClassesArePublicSoThatTheyCanBeReusedElsewhere() {
85-
assertThat(new ByXPath("a").toString()).isEqualTo("By.xpath: a");
86-
assertThat(new ById("a").toString()).isEqualTo("By.id: a");
87-
assertThat(new ByClassName("a").toString()).isEqualTo("By.className: a");
88-
assertThat(new ByLinkText("a").toString()).isEqualTo("By.linkText: a");
89-
assertThat(new ByName("a").toString()).isEqualTo("By.name: a");
90-
assertThat(new ByTagName("a").toString()).isEqualTo("By.tagName: a");
91-
assertThat(new ByCssSelector("a").toString()).isEqualTo("By.cssSelector: a");
92-
assertThat(new ByPartialLinkText("a").toString()).isEqualTo("By.partialLinkText: a");
85+
assertThat(new ByXPath("a")).hasToString("By.xpath: a");
86+
assertThat(new ById("a")).hasToString("By.id: a");
87+
assertThat(new ByClassName("a")).hasToString("By.className: a");
88+
assertThat(new ByLinkText("a")).hasToString("By.linkText: a");
89+
assertThat(new ByName("a")).hasToString("By.name: a");
90+
assertThat(new ByTagName("a")).hasToString("By.tagName: a");
91+
assertThat(new ByCssSelector("a")).hasToString("By.cssSelector: a");
92+
assertThat(new ByPartialLinkText("a")).hasToString("By.partialLinkText: a");
9393
}
9494

9595
// See https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/2917
@@ -101,12 +101,13 @@ public List<WebElement> findElements(SearchContext context) {
101101
return null;
102102
}
103103
};
104-
locator.hashCode();
104+
assertThatNoException().isThrownBy(locator::hashCode);
105105
}
106106

107107
@Test
108108
public void ensureMultipleClassNamesAreNotAccepted() {
109-
assertThatExceptionOfType(InvalidSelectorException.class).isThrownBy(() -> By.className("one two"));
109+
assertThatExceptionOfType(InvalidSelectorException.class)
110+
.isThrownBy(() -> By.className("one two"));
110111
}
111112

112113
@Test
@@ -117,12 +118,9 @@ public void ensureIdIsSerializedProperly() {
117118
Json json = new Json();
118119
Map<String, Object> blob = json.toType(json.toJson(by), MAP_TYPE);
119120

120-
assertThat(blob.get("using")).isEqualTo("css selector");
121-
assertThat(blob.get("value")).isEqualTo("#one\\ two");
121+
assertThat(blob)
122+
.hasSize(2)
123+
.containsEntry("using", "css selector")
124+
.containsEntry("value", "#one\\ two");
122125
}
123-
124-
private interface AllDriver extends SearchContext {
125-
// Place holder
126-
}
127-
128126
}

0 commit comments

Comments
 (0)