1818package org .openqa .selenium .remote ;
1919
2020import com .google .common .collect .ImmutableMap ;
21+
2122import org .junit .jupiter .api .Test ;
2223import org .junit .jupiter .api .Tag ;
2324import org .openqa .selenium .By ;
5051import static org .openqa .selenium .remote .DriverCommand .FIND_ELEMENT ;
5152
5253@ Tag ("UnitTests" )
53- public class AugmenterTest {
54+ class AugmenterTest {
5455
5556 private Augmenter getAugmenter () {
5657 return new Augmenter ();
5758 }
5859
5960 @ Test
60- public void shouldAugmentRotatable () {
61+ void shouldAugmentRotatable () {
6162 final Capabilities caps = new ImmutableCapabilities (CapabilityType .ROTATABLE , true );
6263 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
6364
@@ -68,8 +69,10 @@ public void shouldAugmentRotatable() {
6869 }
6970
7071 @ Test
71- public void shouldAugmentLocationContext () {
72- final Capabilities caps = new ImmutableCapabilities (CapabilityType .SUPPORTS_LOCATION_CONTEXT , true );
72+ void shouldAugmentLocationContext () {
73+ final Capabilities
74+ caps =
75+ new ImmutableCapabilities (CapabilityType .SUPPORTS_LOCATION_CONTEXT , true );
7376 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
7477
7578 WebDriver returned = getAugmenter ().augment (driver );
@@ -79,7 +82,7 @@ public void shouldAugmentLocationContext() {
7982 }
8083
8184 @ Test
82- public void shouldAddInterfaceFromCapabilityIfNecessary () {
85+ void shouldAddInterfaceFromCapabilityIfNecessary () {
8386 final Capabilities caps = new ImmutableCapabilities ("magic.numbers" , true );
8487 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
8588
@@ -92,7 +95,7 @@ public void shouldAddInterfaceFromCapabilityIfNecessary() {
9295 }
9396
9497 @ Test
95- public void shouldNotAddInterfaceWhenBooleanValueForItIsFalse () {
98+ void shouldNotAddInterfaceWhenBooleanValueForItIsFalse () {
9699 Capabilities caps = new ImmutableCapabilities ("magic.numbers" , false );
97100 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
98101
@@ -105,7 +108,7 @@ public void shouldNotAddInterfaceWhenBooleanValueForItIsFalse() {
105108 }
106109
107110 @ Test
108- public void shouldNotUseNonMatchingInterfaces () {
111+ void shouldNotUseNonMatchingInterfaces () {
109112 Capabilities caps = new ImmutableCapabilities ("magic.numbers" , true );
110113 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
111114
@@ -116,7 +119,7 @@ public void shouldNotUseNonMatchingInterfaces() {
116119 }
117120
118121 @ Test
119- public void shouldDelegateToHandlerIfAdded () {
122+ void shouldDelegateToHandlerIfAdded () {
120123 Capabilities caps = new ImmutableCapabilities ("foo" , true );
121124 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
122125
@@ -132,7 +135,7 @@ public void shouldDelegateToHandlerIfAdded() {
132135 }
133136
134137 @ Test
135- public void shouldDelegateUnmatchedMethodCallsToDriverImplementation () {
138+ void shouldDelegateUnmatchedMethodCallsToDriverImplementation () {
136139 Capabilities caps = new ImmutableCapabilities ("magic.numbers" , true );
137140 StubExecutor stubExecutor = new StubExecutor (caps );
138141 stubExecutor .expect (DriverCommand .GET_TITLE , new HashMap <>(), "Title" );
@@ -149,7 +152,7 @@ public void shouldDelegateUnmatchedMethodCallsToDriverImplementation() {
149152 }
150153
151154 @ Test
152- public void proxyShouldNotAppearInStackTraces () {
155+ void proxyShouldNotAppearInStackTraces () {
153156 // This will force the class to be enhanced
154157 final Capabilities caps = new ImmutableCapabilities ("magic.numbers" , true );
155158
@@ -168,21 +171,21 @@ public void proxyShouldNotAppearInStackTraces() {
168171 }
169172
170173 @ Test
171- public void shouldCopyFieldsFromTemplateInstanceIntoChildInstance () {
174+ void shouldCopyFieldsFromTemplateInstanceIntoChildInstance () {
172175 ChildRemoteDriver driver = new ChildRemoteDriver ();
173176 HasMagicNumbers holder = (HasMagicNumbers ) getAugmenter ().augment (driver );
174177
175178 assertThat (holder .getMagicNumber ()).isEqualTo (3 );
176179 }
177180
178181 @ Test
179- public void shouldNotChokeOnFinalFields () {
182+ void shouldNotChokeOnFinalFields () {
180183 WithFinals withFinals = new WithFinals ();
181184 getAugmenter ().augment (withFinals );
182185 }
183186
184187 @ Test
185- public void shouldAllowReflexiveCalls () {
188+ void shouldAllowReflexiveCalls () {
186189 Capabilities caps = new ImmutableCapabilities ("find by magic" , true );
187190 StubExecutor executor = new StubExecutor (caps );
188191 final WebElement element = mock (WebElement .class );
@@ -205,30 +208,33 @@ public void shouldAllowReflexiveCalls() {
205208 }
206209
207210 @ Test
208- public void shouldAugmentMultipleInterfaces () {
211+ void shouldAugmentMultipleInterfaces () {
209212 final Capabilities caps = new ImmutableCapabilities ("magic.numbers" , true ,
210213 "numbers" , true );
211214 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
212215
213216 WebDriver returned = getAugmenter ()
214217 .addDriverAugmentation ("magic.numbers" , HasMagicNumbers .class , (c , exe ) -> () -> 42 )
215- .addDriverAugmentation ("numbers" , HasNumbers .class , (c , exe ) -> webDriver -> {
216- Require .precondition (webDriver instanceof HasMagicNumbers , "Driver must implement HasMagicNumbers" );
217- return ((HasMagicNumbers )webDriver ).getMagicNumber ();
218+ .addDriverAugmentation ("numbers" , HasNumbers .class , (c , exe ) -> webDriver -> {
219+ Require .precondition (webDriver instanceof HasMagicNumbers ,
220+ "Driver must implement HasMagicNumbers" );
221+ return ((HasMagicNumbers ) webDriver ).getMagicNumber ();
218222 })
219223 .augment (driver );
220224
221225 assertThat (returned ).isNotSameAs (driver );
222226 assertThat (returned ).isInstanceOf (HasMagicNumbers .class );
223227 assertThat (returned ).isInstanceOf (HasNumbers .class );
224228
225- int number = ((HasNumbers )returned ).getNumbers (returned );
229+ int number = ((HasNumbers ) returned ).getNumbers (returned );
226230 assertThat (number ).isEqualTo (42 );
227231 }
228232
229233 @ Test
230- public void shouldAugmentWebDriverDecorator () {
231- final Capabilities caps = new ImmutableCapabilities (CapabilityType .SUPPORTS_LOCATION_CONTEXT , true );
234+ void shouldAugmentWebDriverDecorator () {
235+ final Capabilities
236+ caps =
237+ new ImmutableCapabilities (CapabilityType .SUPPORTS_LOCATION_CONTEXT , true );
232238 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
233239
234240 WebDriver decorated = new ModifyTitleWebDriverDecorator ().decorate (driver );
@@ -241,22 +247,23 @@ public void shouldAugmentWebDriverDecorator() {
241247 assertThat (returned ).isNotSameAs (decorated );
242248 assertThat (returned ).isInstanceOf (LocationContext .class );
243249
244- String title = returned .getTitle ();
250+ String title = returned .getTitle ();
245251
246252 assertThat (title ).isEqualTo ("title" );
247253 }
248254
249255 @ Test
250- public void shouldDecorateAugmentedWebDriver () {
256+ void shouldDecorateAugmentedWebDriver () {
251257 final Capabilities caps = new ImmutableCapabilities ("magic.numbers" , true ,
252258 "numbers" , true );
253259 WebDriver driver = new RemoteWebDriver (new StubExecutor (caps ), caps );
254260
255261 WebDriver augmented = getAugmenter ()
256262 .addDriverAugmentation ("magic.numbers" , HasMagicNumbers .class , (c , exe ) -> () -> 42 )
257- .addDriverAugmentation ("numbers" , HasNumbers .class , (c , exe ) -> webDriver -> {
258- Require .precondition (webDriver instanceof HasMagicNumbers , "Driver must implement HasMagicNumbers" );
259- return ((HasMagicNumbers )webDriver ).getMagicNumber ();
263+ .addDriverAugmentation ("numbers" , HasNumbers .class , (c , exe ) -> webDriver -> {
264+ Require .precondition (webDriver instanceof HasMagicNumbers ,
265+ "Driver must implement HasMagicNumbers" );
266+ return ((HasMagicNumbers ) webDriver ).getMagicNumber ();
260267 })
261268 .augment (driver );
262269
@@ -271,11 +278,12 @@ public void shouldDecorateAugmentedWebDriver() {
271278
272279 assertThat (title ).isEqualTo ("title" );
273280
274- int number = ((HasNumbers )decorated ).getNumbers (decorated );
281+ int number = ((HasNumbers ) decorated ).getNumbers (decorated );
275282 assertThat (number ).isEqualTo (42 );
276283 }
277284
278285 private static class ByMagic extends By {
286+
279287 private final String magicWord ;
280288
281289 public ByMagic (String magicWord ) {
@@ -289,17 +297,18 @@ public List<WebElement> findElements(SearchContext context) {
289297 }
290298
291299 public interface FindByMagic {
300+
292301 WebElement findByMagic (String magicWord );
293302 }
294303
295304 @ Test
296- public void shouldBeAbleToAugmentMultipleTimes () {
305+ void shouldBeAbleToAugmentMultipleTimes () {
297306 Capabilities caps = new ImmutableCapabilities ("rotatable" , true , "magic.numbers" , true );
298307
299308 StubExecutor stubExecutor = new StubExecutor (caps );
300309 stubExecutor .expect (DriverCommand .GET_SCREEN_ORIENTATION ,
301- Collections .emptyMap (),
302- ScreenOrientation .PORTRAIT .name ());
310+ Collections .emptyMap (),
311+ ScreenOrientation .PORTRAIT .name ());
303312 RemoteWebDriver driver = new RemoteWebDriver (stubExecutor , caps );
304313
305314 WebDriver augmented = getAugmenter ().augment (driver );
@@ -326,6 +335,7 @@ public void shouldBeAbleToAugmentMultipleTimes() {
326335 }
327336
328337 protected static class StubExecutor implements CommandExecutor {
338+
329339 private final Capabilities capabilities ;
330340 private final List <Data > expected = new ArrayList <>();
331341
@@ -343,7 +353,7 @@ public Response execute(Command command) {
343353
344354 for (Data possibleMatch : expected ) {
345355 if (possibleMatch .commandName .equals (command .getName ()) &&
346- possibleMatch .args .equals (command .getParameters ())) {
356+ possibleMatch .args .equals (command .getParameters ())) {
347357 Response response = new Response (new SessionId ("foo" ));
348358 response .setValue (possibleMatch .returnValue );
349359 return response ;
@@ -358,6 +368,7 @@ public void expect(String commandName, Map<String, ?> args, Object returnValue)
358368 }
359369
360370 private static class Data {
371+
361372 public String commandName ;
362373 public Map <String , ?> args ;
363374 public Object returnValue ;
@@ -371,10 +382,12 @@ public Data(String commandName, Map<String, ?> args, Object returnValue) {
371382 }
372383
373384 public interface MyInterface {
385+
374386 String getHelloWorld ();
375387 }
376388
377389 public static class DetonatingDriver extends RemoteWebDriver {
390+
378391 private Capabilities caps ;
379392
380393 public void setCapabilities (Capabilities caps ) {
@@ -398,10 +411,12 @@ public WebElement findElement(By locator) {
398411 }
399412
400413 public interface HasNumbers {
414+
401415 int getNumbers (WebDriver driver );
402416 }
403417
404418 public static class ChildRemoteDriver extends RemoteWebDriver implements HasMagicNumbers {
419+
405420 private int magicNumber = 3 ;
406421
407422 @ Override
@@ -416,6 +431,7 @@ public int getMagicNumber() {
416431 }
417432
418433 public static class WithFinals extends RemoteWebDriver {
434+
419435 public final String finalField = "FINAL" ;
420436
421437 @ Override
0 commit comments