From 8e24d937238c2d2862970ef8353f32818254b0c3 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 6 Jul 2022 12:47:58 +0530 Subject: [PATCH] [java] Formatting changes in test classes --- .../openqa/selenium/remote/AugmenterTest.java | 76 +++++++++++-------- .../decorators/DecoratedAlertTest.java | 11 +-- .../decorators/DecoratedNavigationTest.java | 13 ++-- .../decorators/DecoratedOptionsTest.java | 29 +++---- .../DecoratedRemoteWebDriverTest.java | 16 ++-- .../decorators/DecoratedSwitchToTest.java | 24 +++--- .../decorators/DecoratedTimeoutsTest.java | 15 ++-- .../DecoratedVirtualAuthenticatorTest.java | 20 ++--- .../decorators/DecoratedWebDriverTest.java | 66 ++++++++-------- .../decorators/DecoratedWebElementTest.java | 49 ++++++------ .../decorators/DecoratedWindowTest.java | 17 +++-- .../support/decorators/IntegrationTest.java | 6 +- .../support/decorators/InterfacesTest.java | 6 +- 13 files changed, 192 insertions(+), 156 deletions(-) diff --git a/java/test/org/openqa/selenium/remote/AugmenterTest.java b/java/test/org/openqa/selenium/remote/AugmenterTest.java index 46bbacb2f2d8c..998f36043ace9 100644 --- a/java/test/org/openqa/selenium/remote/AugmenterTest.java +++ b/java/test/org/openqa/selenium/remote/AugmenterTest.java @@ -18,6 +18,7 @@ package org.openqa.selenium.remote; import com.google.common.collect.ImmutableMap; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Tag; import org.openqa.selenium.By; @@ -50,14 +51,14 @@ import static org.openqa.selenium.remote.DriverCommand.FIND_ELEMENT; @Tag("UnitTests") -public class AugmenterTest { +class AugmenterTest { private Augmenter getAugmenter() { return new Augmenter(); } @Test - public void shouldAugmentRotatable() { + void shouldAugmentRotatable() { final Capabilities caps = new ImmutableCapabilities(CapabilityType.ROTATABLE, true); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); @@ -68,8 +69,10 @@ public void shouldAugmentRotatable() { } @Test - public void shouldAugmentLocationContext() { - final Capabilities caps = new ImmutableCapabilities(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true); + void shouldAugmentLocationContext() { + final Capabilities + caps = + new ImmutableCapabilities(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); WebDriver returned = getAugmenter().augment(driver); @@ -79,7 +82,7 @@ public void shouldAugmentLocationContext() { } @Test - public void shouldAddInterfaceFromCapabilityIfNecessary() { + void shouldAddInterfaceFromCapabilityIfNecessary() { final Capabilities caps = new ImmutableCapabilities("magic.numbers", true); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); @@ -92,7 +95,7 @@ public void shouldAddInterfaceFromCapabilityIfNecessary() { } @Test - public void shouldNotAddInterfaceWhenBooleanValueForItIsFalse() { + void shouldNotAddInterfaceWhenBooleanValueForItIsFalse() { Capabilities caps = new ImmutableCapabilities("magic.numbers", false); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); @@ -105,7 +108,7 @@ public void shouldNotAddInterfaceWhenBooleanValueForItIsFalse() { } @Test - public void shouldNotUseNonMatchingInterfaces() { + void shouldNotUseNonMatchingInterfaces() { Capabilities caps = new ImmutableCapabilities("magic.numbers", true); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); @@ -116,7 +119,7 @@ public void shouldNotUseNonMatchingInterfaces() { } @Test - public void shouldDelegateToHandlerIfAdded() { + void shouldDelegateToHandlerIfAdded() { Capabilities caps = new ImmutableCapabilities("foo", true); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); @@ -132,7 +135,7 @@ public void shouldDelegateToHandlerIfAdded() { } @Test - public void shouldDelegateUnmatchedMethodCallsToDriverImplementation() { + void shouldDelegateUnmatchedMethodCallsToDriverImplementation() { Capabilities caps = new ImmutableCapabilities("magic.numbers", true); StubExecutor stubExecutor = new StubExecutor(caps); stubExecutor.expect(DriverCommand.GET_TITLE, new HashMap<>(), "Title"); @@ -149,7 +152,7 @@ public void shouldDelegateUnmatchedMethodCallsToDriverImplementation() { } @Test - public void proxyShouldNotAppearInStackTraces() { + void proxyShouldNotAppearInStackTraces() { // This will force the class to be enhanced final Capabilities caps = new ImmutableCapabilities("magic.numbers", true); @@ -168,7 +171,7 @@ public void proxyShouldNotAppearInStackTraces() { } @Test - public void shouldCopyFieldsFromTemplateInstanceIntoChildInstance() { + void shouldCopyFieldsFromTemplateInstanceIntoChildInstance() { ChildRemoteDriver driver = new ChildRemoteDriver(); HasMagicNumbers holder = (HasMagicNumbers) getAugmenter().augment(driver); @@ -176,13 +179,13 @@ public void shouldCopyFieldsFromTemplateInstanceIntoChildInstance() { } @Test - public void shouldNotChokeOnFinalFields() { + void shouldNotChokeOnFinalFields() { WithFinals withFinals = new WithFinals(); getAugmenter().augment(withFinals); } @Test - public void shouldAllowReflexiveCalls() { + void shouldAllowReflexiveCalls() { Capabilities caps = new ImmutableCapabilities("find by magic", true); StubExecutor executor = new StubExecutor(caps); final WebElement element = mock(WebElement.class); @@ -205,16 +208,17 @@ public void shouldAllowReflexiveCalls() { } @Test - public void shouldAugmentMultipleInterfaces() { + void shouldAugmentMultipleInterfaces() { final Capabilities caps = new ImmutableCapabilities("magic.numbers", true, "numbers", true); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); WebDriver returned = getAugmenter() .addDriverAugmentation("magic.numbers", HasMagicNumbers.class, (c, exe) -> () -> 42) - .addDriverAugmentation("numbers", HasNumbers.class, (c, exe) -> webDriver -> { - Require.precondition(webDriver instanceof HasMagicNumbers, "Driver must implement HasMagicNumbers"); - return ((HasMagicNumbers)webDriver).getMagicNumber(); + .addDriverAugmentation("numbers", HasNumbers.class, (c, exe) -> webDriver -> { + Require.precondition(webDriver instanceof HasMagicNumbers, + "Driver must implement HasMagicNumbers"); + return ((HasMagicNumbers) webDriver).getMagicNumber(); }) .augment(driver); @@ -222,13 +226,15 @@ public void shouldAugmentMultipleInterfaces() { assertThat(returned).isInstanceOf(HasMagicNumbers.class); assertThat(returned).isInstanceOf(HasNumbers.class); - int number = ((HasNumbers)returned).getNumbers(returned); + int number = ((HasNumbers) returned).getNumbers(returned); assertThat(number).isEqualTo(42); } @Test - public void shouldAugmentWebDriverDecorator() { - final Capabilities caps = new ImmutableCapabilities(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true); + void shouldAugmentWebDriverDecorator() { + final Capabilities + caps = + new ImmutableCapabilities(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); WebDriver decorated = new ModifyTitleWebDriverDecorator().decorate(driver); @@ -241,22 +247,23 @@ public void shouldAugmentWebDriverDecorator() { assertThat(returned).isNotSameAs(decorated); assertThat(returned).isInstanceOf(LocationContext.class); - String title = returned.getTitle(); + String title = returned.getTitle(); assertThat(title).isEqualTo("title"); } @Test - public void shouldDecorateAugmentedWebDriver() { + void shouldDecorateAugmentedWebDriver() { final Capabilities caps = new ImmutableCapabilities("magic.numbers", true, "numbers", true); WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps); WebDriver augmented = getAugmenter() .addDriverAugmentation("magic.numbers", HasMagicNumbers.class, (c, exe) -> () -> 42) - .addDriverAugmentation("numbers", HasNumbers.class, (c, exe) -> webDriver -> { - Require.precondition(webDriver instanceof HasMagicNumbers, "Driver must implement HasMagicNumbers"); - return ((HasMagicNumbers)webDriver).getMagicNumber(); + .addDriverAugmentation("numbers", HasNumbers.class, (c, exe) -> webDriver -> { + Require.precondition(webDriver instanceof HasMagicNumbers, + "Driver must implement HasMagicNumbers"); + return ((HasMagicNumbers) webDriver).getMagicNumber(); }) .augment(driver); @@ -271,11 +278,12 @@ public void shouldDecorateAugmentedWebDriver() { assertThat(title).isEqualTo("title"); - int number = ((HasNumbers)decorated).getNumbers(decorated); + int number = ((HasNumbers) decorated).getNumbers(decorated); assertThat(number).isEqualTo(42); } private static class ByMagic extends By { + private final String magicWord; public ByMagic(String magicWord) { @@ -289,17 +297,18 @@ public List findElements(SearchContext context) { } public interface FindByMagic { + WebElement findByMagic(String magicWord); } @Test - public void shouldBeAbleToAugmentMultipleTimes() { + void shouldBeAbleToAugmentMultipleTimes() { Capabilities caps = new ImmutableCapabilities("rotatable", true, "magic.numbers", true); StubExecutor stubExecutor = new StubExecutor(caps); stubExecutor.expect(DriverCommand.GET_SCREEN_ORIENTATION, - Collections.emptyMap(), - ScreenOrientation.PORTRAIT.name()); + Collections.emptyMap(), + ScreenOrientation.PORTRAIT.name()); RemoteWebDriver driver = new RemoteWebDriver(stubExecutor, caps); WebDriver augmented = getAugmenter().augment(driver); @@ -326,6 +335,7 @@ public void shouldBeAbleToAugmentMultipleTimes() { } protected static class StubExecutor implements CommandExecutor { + private final Capabilities capabilities; private final List expected = new ArrayList<>(); @@ -343,7 +353,7 @@ public Response execute(Command command) { for (Data possibleMatch : expected) { if (possibleMatch.commandName.equals(command.getName()) && - possibleMatch.args.equals(command.getParameters())) { + possibleMatch.args.equals(command.getParameters())) { Response response = new Response(new SessionId("foo")); response.setValue(possibleMatch.returnValue); return response; @@ -358,6 +368,7 @@ public void expect(String commandName, Map args, Object returnValue) } private static class Data { + public String commandName; public Map args; public Object returnValue; @@ -371,10 +382,12 @@ public Data(String commandName, Map args, Object returnValue) { } public interface MyInterface { + String getHelloWorld(); } public static class DetonatingDriver extends RemoteWebDriver { + private Capabilities caps; public void setCapabilities(Capabilities caps) { @@ -398,10 +411,12 @@ public WebElement findElement(By locator) { } public interface HasNumbers { + int getNumbers(WebDriver driver); } public static class ChildRemoteDriver extends RemoteWebDriver implements HasMagicNumbers { + private int magicNumber = 3; @Override @@ -416,6 +431,7 @@ public int getMagicNumber() { } public static class WithFinals extends RemoteWebDriver { + public final String finalField = "FINAL"; @Override diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedAlertTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedAlertTest.java index af835e7ef8dab..17aedb6456427 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedAlertTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedAlertTest.java @@ -33,9 +33,10 @@ import java.util.function.Function; @Tag("UnitTests") -public class DecoratedAlertTest { +class DecoratedAlertTest { private static class Fixture { + WebDriver originalDriver; WebDriver decoratedDriver; WebDriver.TargetLocator originalSwitch; @@ -69,22 +70,22 @@ private void verifyFunction(Function f, R result) { } @Test - public void sendKeys() { + void sendKeys() { verifyFunction($ -> $.sendKeys("test")); } @Test - public void accept() { + void accept() { verifyFunction(Alert::accept); } @Test - public void dismiss() { + void dismiss() { verifyFunction(Alert::dismiss); } @Test - public void getText() { + void getText() { verifyFunction(Alert::getText, "test"); } } diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedNavigationTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedNavigationTest.java index 97ee2d69968e5..e2b2bd4c43388 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedNavigationTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedNavigationTest.java @@ -32,9 +32,10 @@ import java.util.function.Consumer; @Tag("UnitTests") -public class DecoratedNavigationTest { +class DecoratedNavigationTest { private static class Fixture { + WebDriver originalDriver; WebDriver decoratedDriver; WebDriver.Navigation original; @@ -57,28 +58,28 @@ private void verifyFunction(Consumer f) { } @Test - public void toAddressAsString() { + void toAddressAsString() { verifyFunction($ -> $.to("test")); } @Test - public void toAddressAsUrl() throws MalformedURLException { + void toAddressAsUrl() throws MalformedURLException { final URL url = new URL("http://www.selenium2.ru/"); verifyFunction($ -> $.to(url)); } @Test - public void back() { + void back() { verifyFunction(WebDriver.Navigation::back); } @Test - public void forward() { + void forward() { verifyFunction(WebDriver.Navigation::forward); } @Test - public void refresh() { + void refresh() { verifyFunction(WebDriver.Navigation::refresh); } } diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedOptionsTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedOptionsTest.java index f0dbdc2e4d64f..fb1b886d6f516 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedOptionsTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedOptionsTest.java @@ -37,9 +37,10 @@ import java.util.function.Function; @Tag("UnitTests") -public class DecoratedOptionsTest { +class DecoratedOptionsTest { private static class Fixture { + WebDriver originalDriver; WebDriver decoratedDriver; WebDriver.Options original; @@ -69,7 +70,8 @@ private void verifyFunction(Function f, R result) { verifyNoMoreInteractions(fixture.original); } - private void verifyDecoratingFunction(Function f, R result, Consumer p) { + private void verifyDecoratingFunction(Function f, R result, + Consumer p) { Fixture fixture = new Fixture(); when(f.apply(fixture.original)).thenReturn(result); @@ -84,57 +86,58 @@ private void verifyDecoratingFunction(Function f, R re } @Test - public void addCookie() { + void addCookie() { verifyFunction($ -> $.addCookie(new Cookie("name", "value"))); } @Test - public void deleteCookieNamed() { + void deleteCookieNamed() { verifyFunction($ -> $.deleteCookieNamed("test")); } @Test - public void deleteCookie() { + void deleteCookie() { verifyFunction($ -> $.deleteCookie(new Cookie("name", "value"))); } @Test - public void deleteAllCookies() { + void deleteAllCookies() { verifyFunction(WebDriver.Options::deleteAllCookies); } @Test - public void getCookies() { + void getCookies() { Set cookies = new HashSet<>(); cookies.add(new Cookie("name", "value")); verifyFunction(WebDriver.Options::getCookies, cookies); } @Test - public void getCookieNamed() { + void getCookieNamed() { verifyFunction($ -> $.getCookieNamed("test"), new Cookie("name", "value")); } @Test - public void timeouts() { + void timeouts() { WebDriver.Timeouts timeouts = mock(WebDriver.Timeouts.class); - verifyDecoratingFunction(WebDriver.Options::timeouts, timeouts, t -> t.implicitlyWait(Duration.ofSeconds(10))); + verifyDecoratingFunction(WebDriver.Options::timeouts, timeouts, + t -> t.implicitlyWait(Duration.ofSeconds(10))); } @Test - public void imeNotDecorated() { + void imeNotDecorated() { final WebDriver.ImeHandler ime = mock(WebDriver.ImeHandler.class); verifyFunction(WebDriver.Options::ime, ime); } @Test - public void window() { + void window() { final WebDriver.Window window = mock(WebDriver.Window.class); verifyDecoratingFunction(WebDriver.Options::window, window, WebDriver.Window::maximize); } @Test - public void logsNotDecorated() { + void logsNotDecorated() { final Logs logs = mock(Logs.class); verifyFunction(WebDriver.Options::logs, logs); } diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedRemoteWebDriverTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedRemoteWebDriverTest.java index 1c2cf10824b6b..98fa66bcdd467 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedRemoteWebDriverTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedRemoteWebDriverTest.java @@ -40,23 +40,25 @@ import static org.openqa.selenium.json.Json.MAP_TYPE; @Tag("UnitTests") -public class DecoratedRemoteWebDriverTest { +class DecoratedRemoteWebDriverTest { @Test - public void shouldImplementWrapsDriverToProvideAccessToUnderlyingDriver() { + void shouldImplementWrapsDriverToProvideAccessToUnderlyingDriver() { SessionId sessionId = new SessionId(UUID.randomUUID()); RemoteWebDriver originalDriver = mock(RemoteWebDriver.class); when(originalDriver.getSessionId()).thenReturn(sessionId); WebDriver decoratedDriver = new WebDriverDecorator().decorate(originalDriver); - RemoteWebDriver underlying = (RemoteWebDriver) ((WrapsDriver) decoratedDriver).getWrappedDriver(); + RemoteWebDriver + underlying = + (RemoteWebDriver) ((WrapsDriver) decoratedDriver).getWrappedDriver(); assertThat(underlying.getSessionId()).isEqualTo(sessionId); } @Test - public void cannotConvertDecoratedToRemoteWebDriver() { + void cannotConvertDecoratedToRemoteWebDriver() { RemoteWebDriver originalDriver = mock(RemoteWebDriver.class); WebDriver decorated = new WebDriverDecorator().decorate(originalDriver); @@ -65,7 +67,7 @@ public void cannotConvertDecoratedToRemoteWebDriver() { } @Test - public void decoratedDriversShouldImplementWrapsDriver() { + void decoratedDriversShouldImplementWrapsDriver() { RemoteWebDriver originalDriver = mock(RemoteWebDriver.class); WebDriver decorated = new WebDriverDecorator().decorate(originalDriver); @@ -74,7 +76,7 @@ public void decoratedDriversShouldImplementWrapsDriver() { } @Test - public void decoratedElementsShouldImplementWrapsElement() { + void decoratedElementsShouldImplementWrapsElement() { RemoteWebDriver originalDriver = mock(RemoteWebDriver.class); RemoteWebElement originalElement = new RemoteWebElement(); String elementId = UUID.randomUUID().toString(); @@ -90,7 +92,7 @@ public void decoratedElementsShouldImplementWrapsElement() { } @Test - public void canConvertDecoratedRemoteWebElementToJson() { + void canConvertDecoratedRemoteWebElementToJson() { RemoteWebDriver originalDriver = mock(RemoteWebDriver.class); RemoteWebElement originalElement = new RemoteWebElement(); String elementId = UUID.randomUUID().toString(); diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedSwitchToTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedSwitchToTest.java index 19eb6d78cdc9f..5339305c0be34 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedSwitchToTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedSwitchToTest.java @@ -35,9 +35,10 @@ import java.util.function.Function; @Tag("UnitTests") -public class DecoratedSwitchToTest { +class DecoratedSwitchToTest { private static class Fixture { + WebDriver originalDriver; WebDriver decoratedDriver; WebDriver.TargetLocator original; @@ -67,7 +68,8 @@ private void verifyDecoratingFunction(Function void verifyDecoratingFunction(Function f, R result, Consumer p) { + private void verifyDecoratingFunction(Function f, R result, + Consumer p) { Fixture fixture = new Fixture(); when(f.apply(fixture.original)).thenReturn(result); @@ -83,49 +85,49 @@ private void verifyDecoratingFunction(Function f } @Test - public void window() { + void window() { verifyDecoratingFunction($ -> $.window("test")); } @Test - public void newWindow() { + void newWindow() { verifyDecoratingFunction($ -> $.newWindow(WindowType.TAB)); } @Test - public void frameByIndex() { + void frameByIndex() { verifyDecoratingFunction($ -> $.frame(3)); } @Test - public void frameByString() { + void frameByString() { verifyDecoratingFunction($ -> $.frame("test")); } @Test - public void frameByReference() { + void frameByReference() { final WebElement frame = mock(WebElement.class); verifyDecoratingFunction($ -> $.frame(frame)); } @Test - public void parentFrame() { + void parentFrame() { verifyDecoratingFunction(WebDriver.TargetLocator::parentFrame); } @Test - public void defaultContent() { + void defaultContent() { verifyDecoratingFunction(WebDriver.TargetLocator::defaultContent); } @Test - public void activeElement() { + void activeElement() { WebElement active = mock(WebElement.class); verifyDecoratingFunction(WebDriver.TargetLocator::activeElement, active, WebElement::click); } @Test - public void alert() { + void alert() { Alert alert = mock(Alert.class); verifyDecoratingFunction(WebDriver.TargetLocator::alert, alert, Alert::dismiss); } diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedTimeoutsTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedTimeoutsTest.java index 7a5ea3df5671e..c564cb02deb26 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedTimeoutsTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedTimeoutsTest.java @@ -32,9 +32,10 @@ import java.util.function.Consumer; @Tag("UnitTests") -public class DecoratedTimeoutsTest { +class DecoratedTimeoutsTest { private static class Fixture { + WebDriver originalDriver; WebDriver decoratedDriver; WebDriver.Options originalOptions; @@ -60,32 +61,32 @@ private void verifyFunction(Consumer f) { } @Test - public void implicitlyWaitLegacy() { + void implicitlyWaitLegacy() { verifyFunction($ -> $.implicitlyWait(10, TimeUnit.SECONDS)); } @Test - public void implicitlyWait() { + void implicitlyWait() { verifyFunction($ -> $.implicitlyWait(Duration.ofSeconds(10))); } @Test - public void setScriptTimeoutLegacy() { + void setScriptTimeoutLegacy() { verifyFunction($ -> $.setScriptTimeout(10, TimeUnit.SECONDS)); } @Test - public void setScriptTimeout() { + void setScriptTimeout() { verifyFunction($ -> $.setScriptTimeout(Duration.ofSeconds(10))); } @Test - public void pageLoadTimeoutLegacy() { + void pageLoadTimeoutLegacy() { verifyFunction($ -> $.pageLoadTimeout(10, TimeUnit.SECONDS)); } @Test - public void pageLoadTimeout() { + void pageLoadTimeout() { verifyFunction($ -> $.pageLoadTimeout(Duration.ofSeconds(10))); } } diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedVirtualAuthenticatorTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedVirtualAuthenticatorTest.java index bb7dde319762f..1c504d1430dd2 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedVirtualAuthenticatorTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedVirtualAuthenticatorTest.java @@ -39,9 +39,10 @@ import java.util.function.Function; @Tag("UnitTests") -public class DecoratedVirtualAuthenticatorTest { +class DecoratedVirtualAuthenticatorTest { private static class Fixture { + WebDriver originalDriver; WebDriver decoratedDriver; VirtualAuthenticator original; @@ -51,7 +52,8 @@ public Fixture() { original = mock(VirtualAuthenticator.class); originalDriver = mock( WebDriver.class, withSettings().extraInterfaces(HasVirtualAuthenticator.class)); - when(((HasVirtualAuthenticator) originalDriver).addVirtualAuthenticator(any())).thenReturn(original); + when(((HasVirtualAuthenticator) originalDriver).addVirtualAuthenticator(any())) + .thenReturn(original); decoratedDriver = new WebDriverDecorator().decorate(originalDriver); decorated = ((HasVirtualAuthenticator) decoratedDriver) .addVirtualAuthenticator(new VirtualAuthenticatorOptions()); @@ -74,38 +76,38 @@ private void verifyFunction(Function f, R result) { } @Test - public void getId() { + void getId() { verifyFunction(VirtualAuthenticator::getId, "test"); } @Test - public void addCredential() { + void addCredential() { Credential credential = mock(Credential.class); verifyFunction($ -> $.addCredential(credential)); } @Test - public void getCredentials() { + void getCredentials() { verifyFunction(VirtualAuthenticator::getCredentials, new ArrayList<>()); } @Test - public void removeCredentialByByteArray() { + void removeCredentialByByteArray() { verifyFunction($ -> $.removeCredential("test".getBytes())); } @Test - public void removeCredentialByString() { + void removeCredentialByString() { verifyFunction($ -> $.removeCredential("test")); } @Test - public void removeAllCredentials() { + void removeAllCredentials() { verifyFunction(VirtualAuthenticator::removeAllCredentials); } @Test - public void setUserVerified() { + void setUserVerified() { verifyFunction($ -> $.setUserVerified(true)); } } diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedWebDriverTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedWebDriverTest.java index 05430bdf24f31..8bf3351273369 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedWebDriverTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedWebDriverTest.java @@ -49,9 +49,10 @@ import java.util.function.Function; @Tag("UnitTests") -public class DecoratedWebDriverTest { +class DecoratedWebDriverTest { private static class Fixture { + WebDriver original; VirtualAuthenticator originalAuth; WebDriver decorated; @@ -62,25 +63,26 @@ public Fixture() { Interactive.class, HasVirtualAuthenticator.class)); originalAuth = mock(VirtualAuthenticator.class); decorated = new WebDriverDecorator().decorate(original); - when(((HasVirtualAuthenticator) original).addVirtualAuthenticator(any())).thenReturn(originalAuth); + when(((HasVirtualAuthenticator) original).addVirtualAuthenticator(any())) + .thenReturn(originalAuth); } } @Test - public void shouldDecorate() { + void shouldDecorate() { Fixture fixture = new Fixture(); assertThat(fixture.decorated).isNotSameAs(fixture.original); } @Test - public void canConvertDecoratedToString() { + void canConvertDecoratedToString() { Fixture fixture = new Fixture(); when(fixture.original.toString()).thenReturn("driver"); assertThat(fixture.decorated.toString()).isEqualTo("Decorated {driver}"); } @Test - public void canCompareDecorated() { + void canCompareDecorated() { WebDriver original1 = mock(WebDriver.class); WebDriver original2 = mock(WebDriver.class); @@ -97,7 +99,7 @@ public void canCompareDecorated() { } @Test - public void testHashCode() { + void testHashCode() { WebDriver original = mock(WebDriver.class); WebDriver decorated = new WebDriverDecorator().decorate(original); assertThat(decorated.hashCode()).isEqualTo(original.hashCode()); @@ -133,33 +135,33 @@ private void verifyDecoratingFunction(Function f, R result, Co } @Test - public void get() { + void get() { verifyFunction(d -> d.get("http://selenium.dev/")); } @Test - public void getCurrentUrl() { + void getCurrentUrl() { verifyFunction(WebDriver::getCurrentUrl, "http://selenium2.ru/"); } @Test - public void getTitle() { + void getTitle() { verifyFunction(WebDriver::getTitle, "test"); } @Test - public void getPageSource() { + void getPageSource() { verifyFunction(WebDriver::getPageSource, "test"); } @Test - public void findElement() { + void findElement() { final WebElement found = mock(WebElement.class); verifyDecoratingFunction($ -> $.findElement(By.id("test")), found, WebElement::click); } @Test - public void findElementNotFound() { + void findElementNotFound() { Fixture fixture = new Fixture(); when(fixture.original.findElement(any())).thenThrow(NoSuchElementException.class); @@ -168,7 +170,7 @@ public void findElementNotFound() { } @Test - public void findElements() { + void findElements() { Fixture fixture = new Fixture(); WebElement originalElement1 = mock(WebElement.class); WebElement originalElement2 = mock(WebElement.class); @@ -192,90 +194,92 @@ public void findElements() { } @Test - public void close() { + void close() { verifyFunction(WebDriver::close); } @Test - public void quit() { + void quit() { verifyFunction(WebDriver::quit); } @Test - public void getWindowHandle() { + void getWindowHandle() { verifyFunction(WebDriver::getWindowHandle, "test"); } @Test - public void getWindowHandles() { + void getWindowHandles() { Set handles = new HashSet<>(); handles.add("test"); verifyFunction(WebDriver::getWindowHandles, handles); } @Test - public void switchTo() { + void switchTo() { final WebDriver.TargetLocator target = mock(WebDriver.TargetLocator.class); verifyDecoratingFunction(WebDriver::switchTo, target, WebDriver.TargetLocator::defaultContent); } @Test - public void navigate() { + void navigate() { final WebDriver.Navigation navigation = mock(WebDriver.Navigation.class); verifyDecoratingFunction(WebDriver::navigate, navigation, WebDriver.Navigation::refresh); } @Test - public void manage() { + void manage() { final WebDriver.Options options = mock(WebDriver.Options.class); verifyDecoratingFunction(WebDriver::manage, options, WebDriver.Options::deleteAllCookies); } @Test - public void executeScriptThatReturnsAPrimitive() { + void executeScriptThatReturnsAPrimitive() { verifyFunction($ -> ((JavascriptExecutor) $).executeScript("..."), 1); } @Test - public void executeScriptThatReturnsAnElement() { + void executeScriptThatReturnsAnElement() { WebElement element = mock(WebElement.class); - verifyDecoratingFunction($ -> (WebElement) ((JavascriptExecutor) $).executeScript("..."), element, WebElement::click); + verifyDecoratingFunction($ -> (WebElement) ((JavascriptExecutor) $).executeScript("..."), + element, WebElement::click); } @Test - public void executeAsyncScriptThatReturnsAPrimitive() { + void executeAsyncScriptThatReturnsAPrimitive() { verifyFunction($ -> ((JavascriptExecutor) $).executeAsyncScript("..."), 1); } @Test - public void executeAsyncScriptThatReturnsAnElement() { + void executeAsyncScriptThatReturnsAnElement() { WebElement element = mock(WebElement.class); - verifyDecoratingFunction($ -> (WebElement) ((JavascriptExecutor) $).executeAsyncScript("..."), element, WebElement::click); + verifyDecoratingFunction($ -> (WebElement) ((JavascriptExecutor) $).executeAsyncScript("..."), + element, WebElement::click); } @Test - public void getScreenshotAs() { + void getScreenshotAs() { verifyFunction($ -> ((TakesScreenshot) $).getScreenshotAs(OutputType.BASE64), ""); } @Test - public void perform() { + void perform() { verifyFunction($ -> ((Interactive) $).perform(new ArrayList<>())); } @Test - public void resetInputState() { + void resetInputState() { verifyFunction($ -> ((Interactive) $).resetInputState()); } @Test - public void addVirtualAuthenticator() { + void addVirtualAuthenticator() { VirtualAuthenticatorOptions options = new VirtualAuthenticatorOptions(); verifyFunction($ -> ((HasVirtualAuthenticator) $).addVirtualAuthenticator(options)); } @Test - public void removeVirtualAuthenticator() { + void removeVirtualAuthenticator() { VirtualAuthenticator auth = mock(VirtualAuthenticator.class); verifyFunction($ -> ((HasVirtualAuthenticator) $).removeVirtualAuthenticator(auth)); } diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedWebElementTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedWebElementTest.java index 1241612fcf2fd..d389bb19cb525 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedWebElementTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedWebElementTest.java @@ -43,9 +43,10 @@ import java.util.function.Function; @Tag("UnitTests") -public class DecoratedWebElementTest { +class DecoratedWebElementTest { private static class Fixture { + WebDriver originalDriver; WebDriver decoratedDriver; WebElement original; @@ -61,7 +62,7 @@ public Fixture() { } @Test - public void canConvertDecoratedToString() { + void canConvertDecoratedToString() { Fixture fixture = new Fixture(); when(fixture.original.toString()).thenReturn("element"); assertThat(fixture.decorated.toString()).isEqualTo("Decorated {element}"); @@ -97,62 +98,62 @@ private void verifyDecoratingFunction(Function f, R result, C } @Test - public void click() { + void click() { verifyFunction(WebElement::click); } @Test - public void submit() { + void submit() { verifyFunction(WebElement::submit); } @Test - public void sendKeys() { + void sendKeys() { verifyFunction($ -> $.sendKeys("test")); } @Test - public void clear() { + void clear() { verifyFunction(WebElement::clear); } @Test - public void getTagName() { + void getTagName() { verifyFunction(WebElement::getTagName, "div"); } @Test - public void getDomProperty() { + void getDomProperty() { verifyFunction($ -> $.getDomProperty("color"), "red"); } @Test - public void getDomAttribute() { + void getDomAttribute() { verifyFunction($ -> $.getDomAttribute("color"), "red"); } @Test - public void getAttribute() { + void getAttribute() { verifyFunction($ -> $.getAttribute("color"), "red"); } @Test - public void isSelected() { + void isSelected() { verifyFunction(WebElement::isSelected, true); } @Test - public void isEnabled() { + void isEnabled() { verifyFunction(WebElement::isEnabled, true); } @Test - public void getText() { + void getText() { verifyFunction(WebElement::getText, "test"); } @Test - public void findElements() { + void findElements() { Fixture fixture = new Fixture(); WebElement originalElement1 = mock(WebElement.class); WebElement originalElement2 = mock(WebElement.class); @@ -161,7 +162,9 @@ public void findElements() { list.add(originalElement2); when(fixture.original.findElements(By.id("test"))).thenReturn(list); - List decoratedElementList = fixture.decoratedDriver.findElement(By.id("list")).findElements(By.id("test")); + List + decoratedElementList = + fixture.decoratedDriver.findElement(By.id("list")).findElements(By.id("test")); assertThat(originalElement1).isNotSameAs(decoratedElementList.get(0)); assertThat(originalElement2).isNotSameAs(decoratedElementList.get(1)); verify(fixture.original, times(1)).findElements(By.id("test")); @@ -176,13 +179,13 @@ public void findElements() { } @Test - public void findElement() { + void findElement() { final WebElement found = mock(WebElement.class); verifyDecoratingFunction($ -> $.findElement(By.id("test")), found, WebElement::click); } @Test - public void findElementNotFound() { + void findElementNotFound() { Fixture fixture = new Fixture(); when(fixture.original.findElement(any())).thenThrow(NoSuchElementException.class); @@ -192,32 +195,32 @@ public void findElementNotFound() { } @Test - public void isDisplayed() { + void isDisplayed() { verifyFunction(WebElement::isDisplayed, true); } @Test - public void getLocation() { + void getLocation() { verifyFunction(WebElement::getLocation, new Point(10, 20)); } @Test - public void getSize() { + void getSize() { verifyFunction(WebElement::getSize, new Dimension(30, 40)); } @Test - public void getRect() { + void getRect() { verifyFunction(WebElement::getRect, new Rectangle(new Point(10, 20), new Dimension(30, 44))); } @Test - public void getCssValue() { + void getCssValue() { verifyFunction($ -> $.getCssValue("color"), "red"); } @Test - public void getScreenshotAs() { + void getScreenshotAs() { verifyFunction($ -> $.getScreenshotAs(OutputType.BASE64), ""); } } diff --git a/java/test/org/openqa/selenium/support/decorators/DecoratedWindowTest.java b/java/test/org/openqa/selenium/support/decorators/DecoratedWindowTest.java index bbcd7c61bedec..f96abfdbf3012 100644 --- a/java/test/org/openqa/selenium/support/decorators/DecoratedWindowTest.java +++ b/java/test/org/openqa/selenium/support/decorators/DecoratedWindowTest.java @@ -34,9 +34,10 @@ import java.util.function.Function; @Tag("UnitTests") -public class DecoratedWindowTest { +class DecoratedWindowTest { private static class Fixture { + WebDriver originalDriver; WebDriver decoratedDriver; WebDriver.Options originalOptions; @@ -70,37 +71,37 @@ private void verifyFunction(Function f, R result) { } @Test - public void setSize() { + void setSize() { verifyFunction($ -> $.setSize(new Dimension(100, 200))); } @Test - public void setPosition() { + void setPosition() { verifyFunction($ -> $.setPosition(new Point(10, 20))); } @Test - public void getSize() { + void getSize() { verifyFunction(WebDriver.Window::getSize, new Dimension(100, 200)); } @Test - public void getPosition() { + void getPosition() { verifyFunction(WebDriver.Window::getPosition, new Point(10, 20)); } @Test - public void maximize() { + void maximize() { verifyFunction(WebDriver.Window::maximize); } @Test - public void minimize() { + void minimize() { verifyFunction(WebDriver.Window::minimize); } @Test - public void fullscreen() { + void fullscreen() { verifyFunction(WebDriver.Window::fullscreen); } } diff --git a/java/test/org/openqa/selenium/support/decorators/IntegrationTest.java b/java/test/org/openqa/selenium/support/decorators/IntegrationTest.java index ae77385604290..aec409baa5ca6 100644 --- a/java/test/org/openqa/selenium/support/decorators/IntegrationTest.java +++ b/java/test/org/openqa/selenium/support/decorators/IntegrationTest.java @@ -32,7 +32,7 @@ import java.lang.reflect.Method; @Tag("UnitTests") -public class IntegrationTest { +class IntegrationTest { static class CountCalls extends WebDriverDecorator { @@ -58,7 +58,7 @@ public Object call(Decorated target, Method method, Object[] args) throws Thr } @Test - public void canDecorateWebDriverMethods() { + void canDecorateWebDriverMethods() { CountCalls decorator = new CountCalls(); WebDriver originalDriver = mock(WebDriver.class); WebDriver decoratedDriver = decorator.decorate(originalDriver); @@ -69,7 +69,7 @@ public void canDecorateWebDriverMethods() { } @Test - public void canDecorateWebElementMethods() { + void canDecorateWebElementMethods() { CountCalls decorator = new CountCalls(); WebDriver originalDriver = mock(WebDriver.class); WebElement element = mock(WebElement.class); diff --git a/java/test/org/openqa/selenium/support/decorators/InterfacesTest.java b/java/test/org/openqa/selenium/support/decorators/InterfacesTest.java index 45a39a5c0fb92..ee63e40e3f4fa 100644 --- a/java/test/org/openqa/selenium/support/decorators/InterfacesTest.java +++ b/java/test/org/openqa/selenium/support/decorators/InterfacesTest.java @@ -25,14 +25,14 @@ import org.openqa.selenium.WebDriver; @Tag("UnitTests") -public class InterfacesTest { +class InterfacesTest { protected interface SomeOtherInterface {} protected interface ExtendedDriver extends WebDriver, SomeOtherInterface {} @Test - public void shouldNotAddInterfacesNotAvailableInTheOriginalDriver() { + void shouldNotAddInterfacesNotAvailableInTheOriginalDriver() { WebDriver driver = mock(WebDriver.class); assertThat(driver).isNotInstanceOf(SomeOtherInterface.class); @@ -41,7 +41,7 @@ public void shouldNotAddInterfacesNotAvailableInTheOriginalDriver() { } @Test - public void shouldRespectInterfacesAvailableInTheOriginalDriver() { + void shouldRespectInterfacesAvailableInTheOriginalDriver() { WebDriver driver = mock(ExtendedDriver.class); assertThat(driver).isInstanceOf(SomeOtherInterface.class);