Skip to content

Commit

Permalink
Move from guava Supplier to java.util.Supplier
Browse files Browse the repository at this point in the history
And continue our march to Java 8
  • Loading branch information
shs96c committed Feb 9, 2017
1 parent 75a479d commit 76d8f6e
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package com.thoughtworks.selenium.webdriven;

import com.google.common.base.Supplier;

import org.openqa.selenium.WebDriver;

import java.util.function.Supplier;

// Visibility set to package level deliberately
class ExplodingSupplier implements Supplier<WebDriver> {
public WebDriver get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

package com.thoughtworks.selenium.webdriven;

import com.google.common.base.Supplier;

import com.thoughtworks.selenium.DefaultSelenium;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.internal.WrapsDriver;

import java.util.function.Supplier;

public class WebDriverBackedSelenium extends DefaultSelenium
implements HasCapabilities, WrapsDriver {
public WebDriverBackedSelenium(Supplier<WebDriver> maker, String baseUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;

import com.google.common.base.Supplier;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
Expand All @@ -29,18 +28,12 @@

import java.nio.charset.Charset;
import java.util.Collection;
import java.util.List;
import java.util.Map;

class HttpMessage {

private final Multimap<String, String> headers = Multimaps.newListMultimap(
Maps.<String, Collection<String>>newHashMap(), new Supplier<List<String>>() {
@Override
public List<String> get() {
return Lists.newLinkedList();
}
});
Maps.<String, Collection<String>>newHashMap(), Lists::newLinkedList);

private final Map<String, Object> attributes = Maps.newHashMap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.google.common.base.Function;
import com.google.common.base.Supplier;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -41,6 +38,7 @@
import org.openqa.selenium.WebDriver;

import java.util.concurrent.TimeUnit;
import java.util.function.Function;

@RunWith(JUnit4.class)
public class FluentWaitTest {
Expand Down Expand Up @@ -205,12 +203,7 @@ public void timeoutMessageIncludesCustomMessageEvaluatedOnFailure() {

Wait<WebDriver> wait = new FluentWait<>(mockDriver, mockClock, mockSleeper)
.withTimeout(0, TimeUnit.MILLISECONDS)
.withMessage(new Supplier<String>() {
@Override
public String get() {
return state;
}
});
.withMessage(() -> state);

state = "external state";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import static org.openqa.selenium.testing.DevMode.isInDevMode;

import com.google.common.base.Supplier;
import com.google.common.base.Throwables;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;

import java.lang.reflect.InvocationTargetException;
import java.util.function.Supplier;
import java.util.logging.Logger;

public class DefaultDriverSupplier implements Supplier<WebDriver> {
Expand Down Expand Up @@ -59,14 +59,10 @@ public WebDriver get() {
try {
return driverClass.getConstructor(Capabilities.class, Capabilities.class).
newInstance(desiredCapabilities, requiredCapabilities);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw Throwables.propagate(e.getTargetException());
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import static java.util.concurrent.TimeUnit.SECONDS;

import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.base.Throwables;

Expand All @@ -35,6 +33,8 @@
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -79,7 +79,7 @@ public WebDriver get() {
desiredCapabilities, requiredCapabilities);
delegate = createForExternalServer(desiredCapabilities, requiredCapabilities, delegate);

return delegate.or(Suppliers.<WebDriver>ofInstance(null)).get();
return delegate.orElse(Suppliers.ofInstance(null)).get();
}

private static Optional<Supplier<WebDriver>> createForExternalServer(
Expand All @@ -97,7 +97,7 @@ private static Optional<Supplier<WebDriver>> createForExternalServer(
Supplier<WebDriver> defaultSupplier = new DefaultRemoteSupplier(
url, desiredCapabilities, requiredCapabilities);
Supplier<WebDriver> supplier = new ExternalServerDriverSupplier(
url, delegate.or(defaultSupplier));
url, delegate.orElse(defaultSupplier));
return Optional.of(supplier);
}
return delegate;
Expand All @@ -121,7 +121,7 @@ private static Optional<Supplier<WebDriver>> createDelegate(
throw Throwables.propagate(e);
}
}
return Optional.absent();
return Optional.empty();
}

@SuppressWarnings("unchecked")
Expand All @@ -132,12 +132,12 @@ private static Optional<Class<? extends Supplier>> getDelegateClass() {
logger.info("Loading custom supplier: " + delegateClassName);
Class<? extends Supplier> clazz =
(Class<? extends Supplier>) Class.forName(delegateClassName);
return Optional.<Class<? extends Supplier>>of(clazz);
return Optional.of(clazz);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
return Optional.absent();
return Optional.empty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

package org.openqa.selenium.testing.drivers;

import com.google.common.base.Supplier;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.function.Supplier;

public class PhantomJSDriverSupplier implements Supplier<WebDriver> {
private final Capabilities capabilities;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import static org.openqa.selenium.testing.DevMode.isInDevMode;

import com.google.common.base.Supplier;
import com.google.common.base.Throwables;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.lang.reflect.InvocationTargetException;
import java.util.function.Supplier;
import java.util.logging.Logger;

public class ReflectionBackedDriverSupplier implements Supplier<WebDriver> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

package org.openqa.selenium.testing.drivers;

import com.google.common.base.Supplier;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.io.IOException;
import java.util.function.Supplier;

public class RemoteSupplier implements Supplier<WebDriver> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package org.openqa.selenium.testing.drivers;

import com.google.common.base.Supplier;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.UnreachableBrowserException;

import java.util.function.Supplier;

public class SauceBackedDriverSupplier implements Supplier<WebDriver> {

private final Capabilities capabilities;
Expand Down Expand Up @@ -54,6 +54,8 @@ public WebDriver get() {
System.out.println("Waiting 5 sec before the next attempt");
Thread.sleep(5000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

package org.openqa.selenium.testing.drivers;

import com.google.common.base.Supplier;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.function.Supplier;

public class TestInternetExplorerSupplier implements Supplier<WebDriver> {
private Capabilities caps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.testing.drivers;

import com.google.common.base.Supplier;
import com.google.common.collect.Lists;

import org.openqa.selenium.Capabilities;
Expand All @@ -27,6 +26,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.function.Supplier;
import java.util.logging.Level;

public class WebDriverBuilder implements Supplier<WebDriver> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
Expand All @@ -45,6 +44,7 @@
import java.net.URL;
import java.util.Enumeration;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.logging.Handler;
import java.util.logging.Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.openqa.selenium.server.htmlrunner;


import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;

Expand All @@ -33,6 +32,7 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsDriver;

import java.util.function.Supplier;
import java.util.logging.Logger;

class NonReflectiveSteps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.openqa.selenium.server.htmlrunner;


import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;

Expand All @@ -32,6 +31,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;

import com.google.common.base.Supplier;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

Expand All @@ -45,6 +44,7 @@
import org.seleniumhq.jetty9.server.handler.ContextHandler;

import java.io.IOException;
import java.util.function.Supplier;
import java.util.logging.Logger;

import javax.servlet.ServletContext;
Expand Down Expand Up @@ -220,11 +220,7 @@ private static UrlInfo createUrl(String path) {
}

private static Supplier<DriverSessions> createSupplier(final DriverSessions sessions) {
return new Supplier<DriverSessions>() {
public DriverSessions get() {
return sessions;
}
};
return () -> sessions;
}

@Test
Expand Down
8 changes: 1 addition & 7 deletions java/server/test/org/openqa/testing/HeaderContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.testing;

import com.google.common.base.Supplier;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
Expand All @@ -27,7 +26,6 @@
import java.text.ParseException;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

class HeaderContainer {
Expand All @@ -36,11 +34,7 @@ class HeaderContainer {

protected HeaderContainer() {
Map<String, Collection<String>> headersMap = Maps.newHashMap();
this.headers = Multimaps.newListMultimap(headersMap, new Supplier<List<String>>() {
public List<String> get() {
return Lists.newLinkedList();
}
});
this.headers = Multimaps.newListMultimap(headersMap, Lists::newLinkedList);
}

public String getHeader(String name) {
Expand Down

0 comments on commit 76d8f6e

Please sign in to comment.