52
52
import java .time .Instant ;
53
53
import java .util .List ;
54
54
import java .util .Map ;
55
- import java .util .Set ;
56
55
import java .util .UUID ;
57
56
58
57
import static java .net .HttpURLConnection .HTTP_BAD_REQUEST ;
58
+ import static java .util .Collections .emptyList ;
59
+ import static java .util .Collections .emptySet ;
60
+ import static java .util .Collections .singleton ;
61
+ import static java .util .Collections .singletonList ;
62
+ import static java .util .Collections .singletonMap ;
59
63
import static org .assertj .core .api .Assertions .assertThat ;
60
64
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
61
65
import static org .mockito .ArgumentMatchers .argThat ;
62
66
import static org .mockito .Mockito .when ;
63
67
import static org .openqa .selenium .json .Json .MAP_TYPE ;
64
68
import static org .openqa .selenium .remote .http .HttpMethod .POST ;
65
69
70
+ import com .google .common .collect .ImmutableMap ;
71
+
66
72
public class CustomLocatorHandlerTest {
67
73
68
74
private final Secret registrationSecret = new Secret ("cheese" );
@@ -85,11 +91,12 @@ public void partiallyBuildNode() {
85
91
public void shouldRequireInputToHaveAUsingParameter () {
86
92
Node node = nodeBuilder .build ();
87
93
88
- HttpHandler handler = new org .openqa .selenium .grid .node .CustomLocatorHandler (node , registrationSecret , Set .of ());
94
+ HttpHandler handler = new org .openqa .selenium .grid .node .CustomLocatorHandler (
95
+ node , registrationSecret , emptySet ());
89
96
90
97
HttpResponse res = handler .execute (
91
98
new HttpRequest (POST , "/session/1234/element" )
92
- .setContent (Contents .asJson (Map . of ("value" , "1234" ))));
99
+ .setContent (Contents .asJson (singletonMap ("value" , "1234" ))));
93
100
94
101
assertThat (res .getStatus ()).isEqualTo (HTTP_BAD_REQUEST );
95
102
assertThatExceptionOfType (InvalidArgumentException .class ).isThrownBy (() -> Values .get (res , MAP_TYPE ));
@@ -99,11 +106,12 @@ public void shouldRequireInputToHaveAUsingParameter() {
99
106
public void shouldRequireInputToHaveAValueParameter () {
100
107
Node node = nodeBuilder .build ();
101
108
102
- HttpHandler handler = new org .openqa .selenium .grid .node .CustomLocatorHandler (node , registrationSecret , Set .of ());
109
+ HttpHandler handler = new org .openqa .selenium .grid .node .CustomLocatorHandler (
110
+ node , registrationSecret , emptySet ());
103
111
104
112
HttpResponse res = handler .execute (
105
113
new HttpRequest (POST , "/session/1234/element" )
106
- .setContent (Contents .asJson (Map . of ("using" , "magic" ))));
114
+ .setContent (Contents .asJson (singletonMap ("using" , "magic" ))));
107
115
108
116
assertThat (res .getStatus ()).isEqualTo (HTTP_BAD_REQUEST );
109
117
assertThatExceptionOfType (InvalidArgumentException .class ).isThrownBy (() -> Values .get (res , MAP_TYPE ));
@@ -113,11 +121,12 @@ public void shouldRequireInputToHaveAValueParameter() {
113
121
public void shouldRejectRequestWithAnUnknownLocatorMechanism () {
114
122
Node node = nodeBuilder .build ();
115
123
116
- HttpHandler handler = new org .openqa .selenium .grid .node .CustomLocatorHandler (node , registrationSecret , Set .of ());
124
+ HttpHandler handler = new org .openqa .selenium .grid .node .CustomLocatorHandler (
125
+ node , registrationSecret , emptySet ());
117
126
118
127
HttpResponse res = handler .execute (
119
128
new HttpRequest (POST , "/session/1234/element" )
120
- .setContent (Contents .asJson (Map .of (
129
+ .setContent (Contents .asJson (ImmutableMap .of (
121
130
"using" , "cheese" ,
122
131
"value" , "tasty" ))));
123
132
@@ -136,7 +145,7 @@ public void shouldCallTheGivenLocatorForALocator() {
136
145
HttpHandler handler = new org .openqa .selenium .grid .node .CustomLocatorHandler (
137
146
node ,
138
147
registrationSecret ,
139
- Set . of (new CustomLocator () {
148
+ singleton (new CustomLocator () {
140
149
@ Override
141
150
public String getLocatorName () {
142
151
return "cheese" ;
@@ -147,15 +156,15 @@ public By createBy(Object usingParameter) {
147
156
return new By () {
148
157
@ Override
149
158
public List <WebElement > findElements (SearchContext context ) {
150
- return List . of ();
159
+ return emptyList ();
151
160
}
152
161
};
153
162
}
154
163
}));
155
164
156
165
HttpResponse res = handler .with (new ErrorFilter ()).execute (
157
166
new HttpRequest (POST , "/session/1234/element" )
158
- .setContent (Contents .asJson (Map .of (
167
+ .setContent (Contents .asJson (ImmutableMap .of (
159
168
"using" , "cheese" ,
160
169
"value" , "tasty" ))));
161
170
@@ -171,13 +180,13 @@ public void shouldBeAbleToUseNodeAsWebDriver() {
171
180
.thenReturn (
172
181
new HttpResponse ()
173
182
.addHeader ("Content-Type" , Json .JSON_UTF_8 )
174
- .setContent (Contents .asJson (Map . of (
175
- "value" , List . of ( Map . of (Dialect .W3C .getEncodedElementKey (), elementId ))))));
183
+ .setContent (Contents .asJson (singletonMap (
184
+ "value" , singletonList ( singletonMap (Dialect .W3C .getEncodedElementKey (), elementId ))))));
176
185
177
186
HttpHandler handler = new org .openqa .selenium .grid .node .CustomLocatorHandler (
178
187
node ,
179
188
registrationSecret ,
180
- Set . of (new CustomLocator () {
189
+ singleton (new CustomLocator () {
181
190
@ Override
182
191
public String getLocatorName () {
183
192
return "cheese" ;
@@ -191,7 +200,7 @@ public By createBy(Object usingParameter) {
191
200
192
201
HttpResponse res = handler .execute (
193
202
new HttpRequest (POST , "/session/1234/elements" )
194
- .setContent (Contents .asJson (Map .of (
203
+ .setContent (Contents .asJson (ImmutableMap .of (
195
204
"using" , "cheese" ,
196
205
"value" , "tasty" ))));
197
206
@@ -210,13 +219,13 @@ public void shouldBeAbleToRootASearchWithinAnElement() {
210
219
.thenReturn (
211
220
new HttpResponse ()
212
221
.addHeader ("Content-Type" , Json .JSON_UTF_8 )
213
- .setContent (Contents .asJson (Map . of (
214
- "value" , List . of ( Map . of (Dialect .W3C .getEncodedElementKey (), elementId ))))));
222
+ .setContent (Contents .asJson (singletonMap (
223
+ "value" , singletonList ( singletonMap (Dialect .W3C .getEncodedElementKey (), elementId ))))));
215
224
216
225
HttpHandler handler = new CustomLocatorHandler (
217
226
node ,
218
227
registrationSecret ,
219
- Set . of (new CustomLocator () {
228
+ singleton (new CustomLocator () {
220
229
@ Override
221
230
public String getLocatorName () {
222
231
return "cheese" ;
@@ -230,7 +239,7 @@ public By createBy(Object usingParameter) {
230
239
231
240
HttpResponse res = handler .execute (
232
241
new HttpRequest (POST , "/session/1234/element/234345/elements" )
233
- .setContent (Contents .asJson (Map .of (
242
+ .setContent (Contents .asJson (ImmutableMap .of (
234
243
"using" , "cheese" ,
235
244
"value" , "tasty" ))));
236
245
0 commit comments