Skip to content

Commit

Permalink
[java] Formatting changes in test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Jul 6, 2022
1 parent 0a2a4a9 commit 8e24d93
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 156 deletions.
76 changes: 46 additions & 30 deletions java/test/org/openqa/selenium/remote/AugmenterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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");
Expand All @@ -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);

Expand All @@ -168,21 +171,21 @@ public void proxyShouldNotAppearInStackTraces() {
}

@Test
public void shouldCopyFieldsFromTemplateInstanceIntoChildInstance() {
void shouldCopyFieldsFromTemplateInstanceIntoChildInstance() {
ChildRemoteDriver driver = new ChildRemoteDriver();
HasMagicNumbers holder = (HasMagicNumbers) getAugmenter().augment(driver);

assertThat(holder.getMagicNumber()).isEqualTo(3);
}

@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);
Expand All @@ -205,30 +208,33 @@ 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);

assertThat(returned).isNotSameAs(driver);
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);
Expand All @@ -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);

Expand All @@ -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) {
Expand All @@ -289,17 +297,18 @@ public List<WebElement> 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);
Expand All @@ -326,6 +335,7 @@ public void shouldBeAbleToAugmentMultipleTimes() {
}

protected static class StubExecutor implements CommandExecutor {

private final Capabilities capabilities;
private final List<Data> expected = new ArrayList<>();

Expand All @@ -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;
Expand All @@ -358,6 +368,7 @@ public void expect(String commandName, Map<String, ?> args, Object returnValue)
}

private static class Data {

public String commandName;
public Map<String, ?> args;
public Object returnValue;
Expand All @@ -371,10 +382,12 @@ public Data(String commandName, Map<String, ?> args, Object returnValue) {
}

public interface MyInterface {

String getHelloWorld();
}

public static class DetonatingDriver extends RemoteWebDriver {

private Capabilities caps;

public void setCapabilities(Capabilities caps) {
Expand All @@ -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
Expand All @@ -416,6 +431,7 @@ public int getMagicNumber() {
}

public static class WithFinals extends RemoteWebDriver {

public final String finalField = "FINAL";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,22 +70,22 @@ private <R> void verifyFunction(Function<Alert, R> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,28 +58,28 @@ private void verifyFunction(Consumer<WebDriver.Navigation> 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);
}
}
Loading

0 comments on commit 8e24d93

Please sign in to comment.