27
27
28
28
import static org .assertj .core .api .Assertions .assertThat ;
29
29
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 ;
31
31
import static org .mockito .Mockito .mock ;
32
32
import static org .mockito .Mockito .verify ;
33
33
import static org .mockito .Mockito .verifyNoMoreInteractions ;
@@ -46,7 +46,7 @@ public class ByTest {
46
46
47
47
@ Test
48
48
public void shouldUseFindsByNameToLocateElementsByName () {
49
- final AllDriver driver = mock (AllDriver .class );
49
+ final SearchContext driver = mock (SearchContext .class );
50
50
51
51
By .cssSelector ("cheese" ).findElement (driver );
52
52
By .cssSelector ("peas" ).findElements (driver );
@@ -58,7 +58,7 @@ public void shouldUseFindsByNameToLocateElementsByName() {
58
58
59
59
@ Test
60
60
public void shouldUseXpathLocateElementsByXpath () {
61
- AllDriver driver = mock (AllDriver .class );
61
+ SearchContext driver = mock (SearchContext .class );
62
62
63
63
By .xpath (".//*[@name = 'cheese']" ).findElement (driver );
64
64
By .xpath (".//*[@name = 'peas']" ).findElements (driver );
@@ -70,7 +70,7 @@ public void shouldUseXpathLocateElementsByXpath() {
70
70
71
71
@ Test
72
72
public void searchesByTagNameIfSupported () {
73
- AllDriver context = mock (AllDriver .class );
73
+ SearchContext context = mock (SearchContext .class );
74
74
75
75
By .tagName ("foo" ).findElement (context );
76
76
By .tagName ("bar" ).findElements (context );
@@ -82,14 +82,14 @@ public void searchesByTagNameIfSupported() {
82
82
83
83
@ Test
84
84
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" );
93
93
}
94
94
95
95
// See https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/2917
@@ -101,12 +101,13 @@ public List<WebElement> findElements(SearchContext context) {
101
101
return null ;
102
102
}
103
103
};
104
- locator . hashCode ( );
104
+ assertThatNoException (). isThrownBy ( locator :: hashCode );
105
105
}
106
106
107
107
@ Test
108
108
public void ensureMultipleClassNamesAreNotAccepted () {
109
- assertThatExceptionOfType (InvalidSelectorException .class ).isThrownBy (() -> By .className ("one two" ));
109
+ assertThatExceptionOfType (InvalidSelectorException .class )
110
+ .isThrownBy (() -> By .className ("one two" ));
110
111
}
111
112
112
113
@ Test
@@ -117,12 +118,9 @@ public void ensureIdIsSerializedProperly() {
117
118
Json json = new Json ();
118
119
Map <String , Object > blob = json .toType (json .toJson (by ), MAP_TYPE );
119
120
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" );
122
125
}
123
-
124
- private interface AllDriver extends SearchContext {
125
- // Place holder
126
- }
127
-
128
126
}
0 commit comments