@@ -165,9 +165,8 @@ public void testConstructorEqualsDefaultConfig() {
165
165
166
166
@ Test
167
167
public void testAsJson () {
168
- final String [] args = new String [] { "-capabilities" , "browserName=chrome,platform=linux" };
169
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
170
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
168
+ GridNodeConfiguration gnc = parseCliOptions (
169
+ "-capabilities" , "browserName=chrome,platform=linux" );
171
170
172
171
assertEquals ("{\" capabilities\" :"
173
172
+ "[{\" browserName\" :\" chrome\" ,\" platform\" :\" LINUX\" }],"
@@ -207,10 +206,8 @@ public void testWithCapabilitiesArgs() {
207
206
208
207
@ Test
209
208
public void testWithCapabilitiesArgsWithExtraSpacing () {
210
- final String [] args = new String [] { "-capabilities" ,
211
- "browserName= chrome, platform =linux, maxInstances=10, boolean = false " };
212
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
213
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
209
+ GridNodeConfiguration gnc = parseCliOptions (
210
+ "-capabilities" , "browserName= chrome, platform =linux, maxInstances=10, boolean = false " );
214
211
assertTrue (gnc .capabilities .size () == 1 );
215
212
assertEquals ("chrome" , gnc .capabilities .get (0 ).getBrowserName ());
216
213
assertEquals (10L , gnc .capabilities .get (0 ).getCapability ("maxInstances" ));
@@ -220,25 +217,19 @@ public void testWithCapabilitiesArgsWithExtraSpacing() {
220
217
221
218
@ Test
222
219
public void testGetHubHost () {
223
- final String [] args = new String []{"-hubHost" , "dummyhost" , "-hubPort" , "1234" };
224
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
225
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
220
+ GridNodeConfiguration gnc = parseCliOptions ("-hubHost" , "dummyhost" , "-hubPort" , "1234" );
226
221
assertEquals ("dummyhost" , gnc .getHubHost ());
227
222
}
228
223
229
224
@ Test
230
225
public void testGetHubHostFromHubOption () {
231
- final String [] args = new String []{"-hub" , "http://dummyhost:1234/wd/hub" };
232
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
233
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
226
+ GridNodeConfiguration gnc = parseCliOptions ("-hub" , "http://dummyhost:1234/wd/hub" );
234
227
assertEquals ("dummyhost" , gnc .getHubHost ());
235
228
}
236
229
237
230
@ Test
238
231
public void testOneOfHubOrHubHostShouldBePresent () {
239
- final String [] args = new String []{"-hubPort" , "1234" };
240
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
241
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
232
+ GridNodeConfiguration gnc = parseCliOptions ("-hubPort" , "1234" );
242
233
Throwable t = catchThrowable (gnc ::getHubHost );
243
234
assertThat (t , CoreMatchers .instanceOf (RuntimeException .class ));
244
235
t = catchThrowable (gnc ::getHubPort );
@@ -247,34 +238,26 @@ public void testOneOfHubOrHubHostShouldBePresent() {
247
238
248
239
@ Test
249
240
public void testHubOptionHasPrecedenceOverHubHost () {
250
- final String [] args = new String []{"-hub" , "http://smarthost:4321/wd/hub" ,
251
- "-hubHost" , "dummyhost" , "-hubPort" , "1234" };
252
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
253
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
241
+ GridNodeConfiguration gnc = parseCliOptions (
242
+ "-hub" , "http://smarthost:4321/wd/hub" , "-hubHost" , "dummyhost" , "-hubPort" , "1234" );
254
243
assertEquals ("smarthost" , gnc .getHubHost ());
255
244
}
256
245
257
246
@ Test
258
247
public void testGetHubPort () {
259
- final String [] args = new String []{"-hubHost" , "dummyhost" , "-hubPort" , "1234" };
260
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
261
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
248
+ GridNodeConfiguration gnc = parseCliOptions ("-hubHost" , "dummyhost" , "-hubPort" , "1234" );
262
249
assertEquals (1234 , gnc .getHubPort ().intValue ());
263
250
}
264
251
265
252
@ Test
266
253
public void testGetHubPortFromHubOption () {
267
- final String [] args = new String []{"-hub" , "http://dummyhost:1234/wd/hub" };
268
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
269
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
254
+ GridNodeConfiguration gnc = parseCliOptions ("-hub" , "http://dummyhost:1234/wd/hub" );
270
255
assertEquals (1234 , gnc .getHubPort ().intValue ());
271
256
}
272
257
273
258
@ Test
274
259
public void testOneOfHubOrHubPortShouldBePresent () {
275
- final String [] args = new String []{"-hubHost" , "dummyhost" };
276
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
277
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
260
+ GridNodeConfiguration gnc = parseCliOptions ("-hubHost" , "dummyhost" );
278
261
Throwable t = catchThrowable (gnc ::getHubHost );
279
262
assertThat (t , CoreMatchers .instanceOf (RuntimeException .class ));
280
263
t = catchThrowable (gnc ::getHubPort );
@@ -283,10 +266,8 @@ public void testOneOfHubOrHubPortShouldBePresent() {
283
266
284
267
@ Test
285
268
public void testHubOptionHasPrecedenceOverHubPort () {
286
- final String [] args = new String []{"-hub" , "http://smarthost:4321/wd/hub" ,
287
- "-hubHost" , "dummyhost" , "-hubPort" , "1234" };
288
- GridNodeConfiguration gnc = new GridNodeConfiguration ();
289
- JCommander .newBuilder ().addObject (gnc ).build ().parse (args );
269
+ GridNodeConfiguration gnc = parseCliOptions (
270
+ "-hub" , "http://smarthost:4321/wd/hub" , "-hubHost" , "dummyhost" , "-hubPort" , "1234" );
290
271
assertEquals (4321 , gnc .getHubPort ().intValue ());
291
272
}
292
273
@@ -375,4 +356,9 @@ public void testFixupCapabilitiesAddsUUID() {
375
356
.allMatch (cap -> cap .getCapability (GridNodeConfiguration .CONFIG_UUID_CAPABILITY ) != null ));
376
357
}
377
358
359
+ private GridNodeConfiguration parseCliOptions (String ... args ) {
360
+ GridNodeConfiguration config = new GridNodeConfiguration ();
361
+ JCommander .newBuilder ().addObject (config ).build ().parse (args );
362
+ return config ;
363
+ }
378
364
}
0 commit comments