Skip to content

Commit e349318

Browse files
committed
[java] Test code cleanup, updating to Java 8 features
1 parent 982baeb commit e349318

14 files changed

+28
-35
lines changed

java/client/test/org/openqa/selenium/WaitingConditions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ boolean compareText(String expectedValue, String actualValue) {
7878
}
7979

8080
public static ExpectedCondition<String> elementTextToEqual(final By locator, final String value) {
81-
return new ExpectedCondition<String>() {
81+
return new ExpectedCondition<>() {
8282

8383
@Override
8484
public String apply(WebDriver driver) {
@@ -100,7 +100,7 @@ public String toString() {
100100

101101
public static ExpectedCondition<String> elementValueToEqual(
102102
final WebElement element, final String expectedValue) {
103-
return new ExpectedCondition<String>() {
103+
return new ExpectedCondition<>() {
104104

105105
private String lastValue = "";
106106

@@ -121,7 +121,7 @@ public String toString() {
121121
}
122122

123123
public static ExpectedCondition<String> pageSourceToContain(final String expectedText) {
124-
return new ExpectedCondition<String>() {
124+
return new ExpectedCondition<>() {
125125
@Override
126126
public String apply(WebDriver driver) {
127127
String source = driver.getPageSource();
@@ -141,7 +141,7 @@ public String toString() {
141141

142142
public static ExpectedCondition<Point> elementLocationToBe(
143143
final WebElement element, final Point expectedLocation) {
144-
return new ExpectedCondition<Point>() {
144+
return new ExpectedCondition<>() {
145145
private Point currentLocation = new Point(0, 0);
146146

147147
@Override
@@ -181,7 +181,7 @@ public static ExpectedCondition<String> newWindowIsOpened(final Set<String> orig
181181
}
182182

183183
public static ExpectedCondition<WebDriver> windowToBeSwitchedToWithName(final String windowName) {
184-
return new ExpectedCondition<WebDriver>() {
184+
return new ExpectedCondition<>() {
185185

186186
@Override
187187
public WebDriver apply(WebDriver driver) {

java/client/test/org/openqa/selenium/atoms/InputAtomsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class InputAtomsTest {
4141
@Test
4242
public void exportsTheExpectedNames() throws IOException {
4343
final String source = JavaScriptLoader.loadResource(RESOURCE_PATH);
44-
ContextFactory.getGlobal().call(new ContextAction() {
44+
ContextFactory.getGlobal().call(new ContextAction<>() {
4545
private ScriptableObject global;
4646

4747
@Override

java/client/test/org/openqa/selenium/build/InProject.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.nio.file.Path;
2727
import java.nio.file.Paths;
2828
import java.util.Objects;
29-
import java.util.stream.Collectors;
3029
import java.util.stream.Stream;
3130

3231
public class InProject {
@@ -44,7 +43,7 @@ public static Path locate(String... paths) {
4443
.map(path -> Paths.get(path))
4544
.filter(path -> Files.exists(path))
4645
.findFirst()
47-
.map(path -> path.toAbsolutePath())
46+
.map(Path::toAbsolutePath)
4847
.orElseGet(() -> {
4948
Path root = findProjectRoot();
5049
return Stream.of(paths)
@@ -55,7 +54,7 @@ public static Path locate(String... paths) {
5554
.filter(Objects::nonNull)
5655
.findFirst().orElseThrow(() -> new WebDriverException(new FileNotFoundException(
5756
String.format("Could not find any of %s in the project",
58-
Stream.of(paths).collect(Collectors.joining(","))))));
57+
String.join(",", paths)))));
5958
});
6059
}
6160

java/client/test/org/openqa/selenium/devtools/ChromeDevToolsFetchTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void testFulfillRequest() {
5454
Optional.empty(),
5555
Optional.empty()));
5656
});
57-
List<RequestPattern> patterns = new ArrayList();
57+
List<RequestPattern> patterns = new ArrayList<>();
5858
patterns.add(new RequestPattern("*://*.*", ResourceType.EventSource, RequestStage.Request));
5959
devTools.send(enable(Optional.of(patterns), Optional.empty()));
6060
chromeDriver.get(appServer.whereIs("simpleTest.html"));
@@ -79,7 +79,7 @@ public void testContinueRequest() {
7979
Assert.assertNotNull(stream);
8080

8181
});
82-
List<RequestPattern> patterns = new ArrayList();
82+
List<RequestPattern> patterns = new ArrayList<>();
8383
patterns.add(new RequestPattern("*://*.*", ResourceType.EventSource, RequestStage.Request));
8484
devTools.send(enable(Optional.of(patterns), Optional.empty()));
8585
chromeDriver.get(appServer.whereIs("simpleTest.html"));
@@ -93,7 +93,7 @@ public void testFailRequest() {
9393
Assert.assertNotNull(p);
9494
devTools.send(failRequest(p.getRequestId(), ErrorReason.BlockedByClient));
9595
});
96-
List<RequestPattern> patterns = new ArrayList();
96+
List<RequestPattern> patterns = new ArrayList<>();
9797
patterns.add(new RequestPattern("*://*.*", ResourceType.EventSource, RequestStage.Request));
9898
devTools.send(enable(Optional.of(patterns), Optional.empty()));
9999
chromeDriver.get(appServer.whereIs("simpleTest.html"));

java/client/test/org/openqa/selenium/devtools/ChromeDevToolsTargetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void getTargetAndSendMessageToTarget() {
7979
devTools.addListener(receivedMessageFromTarget(), this::validateMessage);
8080
allTargets = devTools.send(getTargets());
8181
validateTargetsInfos(allTargets);
82-
ArrayList<TargetInfo> listTargets = new ArrayList(allTargets);
82+
ArrayList<TargetInfo> listTargets = new ArrayList<>(allTargets);
8383
validateTarget(listTargets.get(0));
8484
targetInfo = listTargets.get(0);
8585
devTools.send(activateTarget(targetInfo.getTargetId()));

java/client/test/org/openqa/selenium/environment/webserver/SleepingHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SleepingHandler implements HttpHandler {
3333
@Override
3434
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
3535
String duration = req.getQueryParameter("time");
36-
long timeout = Long.valueOf(duration) * 1000;
36+
long timeout = Long.parseLong(duration) * 1000;
3737

3838
reallySleep(timeout);
3939

java/client/test/org/openqa/selenium/environment/webserver/SleepingServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class SleepingServlet extends HttpServlet {
3232
protected void doGet(HttpServletRequest request, HttpServletResponse response)
3333
throws IOException {
3434
String duration = request.getParameter("time");
35-
long timeout = Long.valueOf(duration) * 1000;
35+
long timeout = Long.parseLong(duration) * 1000;
3636

3737
reallySleep(timeout);
3838

java/client/test/org/openqa/selenium/environment/webserver/StaticContent.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,13 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
6666
res.setStatus(200);
6767
res.setHeader("Content-Type", "text/html");
6868
try {
69-
Files.walk(dest, 0).forEach(
70-
path -> {
71-
content.append("<p><a href=\"")
72-
.append(String.format("%s/%s", req.getUri(), path.getFileName()))
73-
.append("\">")
74-
.append(path.getFileName())
75-
.append("</a>");
76-
}
77-
);
69+
Files.walk(dest, 0).forEach(path -> content
70+
.append("<p><a href=\"")
71+
.append(String.format("%s/%s", req.getUri(), path.getFileName()))
72+
.append("\">")
73+
.append(path.getFileName())
74+
.append("</a>")
75+
);
7876

7977
res.setContent(utf8String(content.toString()));
8078
return res;

java/client/test/org/openqa/selenium/interactions/BasicMouseInterfaceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private boolean fuzzyPositionMatching(int expectedX, int expectedY, String locat
493493

494494
private ExpectedCondition<Boolean> fuzzyMatchingOfCoordinates(
495495
final WebElement element, final int x, final int y) {
496-
return new ExpectedCondition<Boolean>() {
496+
return new ExpectedCondition<>() {
497497
@Override
498498
public Boolean apply(WebDriver ignored) {
499499
return fuzzyPositionMatching(x, y, element.getText());

java/client/test/org/openqa/selenium/support/ui/FluentWaitTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void timeoutMessageIncludesToStringOfCondition() {
196196
"Expected condition failed: waiting for toString called "
197197
+ "(tried for 0 second(s) with 500 milliseconds interval)");
198198

199-
Function<Object, Boolean> condition = new Function<Object, Boolean>() {
199+
Function<Object, Boolean> condition = new Function<>() {
200200
@Override
201201
public Boolean apply(Object ignored) {
202202
return false;
@@ -241,7 +241,7 @@ public void callsDeprecatedHandlerForRuntimeExceptions() {
241241
when(mockCondition.apply(mockDriver)).thenThrow(exception);
242242

243243
final TestException sentinelException = new TestException();
244-
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(mockDriver, mockClock, mockSleeper) {
244+
FluentWait<WebDriver> wait = new FluentWait<>(mockDriver, mockClock, mockSleeper) {
245245
@Override
246246
protected RuntimeException timeoutException(String message, Throwable lastException) {
247247
throw sentinelException;

0 commit comments

Comments
 (0)