Skip to content

Commit

Permalink
Replaced Guava Optional with Java 8 Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Feb 7, 2018
1 parent 0318e40 commit a05f7e6
Show file tree
Hide file tree
Showing 127 changed files with 455 additions and 526 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ subprojects {
}

shadowJar {
classifier = 'with-dependencies'
classifier = null
}

relocate 'com.google.common', 'net.serenitybdd.shadow.com.google.common'
Expand Down Expand Up @@ -375,7 +375,7 @@ subprojects {

println "Publishing with shaded dependencies: $project.name:$project.group:$project.version"

from components.shadow
from components.java

artifact sourcesJar {
classifier "sources"
Expand Down Expand Up @@ -436,6 +436,4 @@ subprojects {
{{/tags}}
""";
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.ant;

import com.google.common.base.Optional;
import net.serenitybdd.ant.util.PathProcessor;
import net.thucydides.core.reports.html.HtmlAggregateStoryReporter;
import org.apache.tools.ant.BuildException;
Expand All @@ -10,6 +9,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

public class SerenityReportingTask extends Task {

Expand Down Expand Up @@ -50,7 +50,7 @@ public Path getSourceDirectoryFile() {
}

private String getSourceDirectory() {
return Optional.fromNullable(sourceDirectory).or(DEFAULT_SOURCE);
return Optional.ofNullable(sourceDirectory).orElse(DEFAULT_SOURCE);
}

public void setSourceDirectory(String sourceDirectory) {
Expand Down Expand Up @@ -87,11 +87,11 @@ private String normalizedPath(String directoryPath) {
}

public Path getOutputDirectoryFile() {
return Paths.get(normalizedPath(getOutputDirectory().or(getSourceDirectory())));
return Paths.get(normalizedPath(getOutputDirectory().orElse(getSourceDirectory())));
}

private Optional<String> getOutputDirectory() {
return Optional.fromNullable(outputDirectory);
private java.util.Optional<String> getOutputDirectory() {
return java.util.Optional.ofNullable(outputDirectory);
}

public void execute() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.core.history;

import com.google.common.base.Optional;
import net.serenitybdd.core.collect.NewMap;
import com.google.inject.Inject;
import net.thucydides.core.guice.Injectors;
Expand Down Expand Up @@ -48,7 +47,7 @@ public FileSystemTestOutcomeSummaryRecorder(EnvironmentVariables environmentVari
*/
public FileSystemTestOutcomeSummaryRecorder(Path historyDirectory, Boolean deletePreviousHistory) {
this.historyDirectory = historyDirectory;
this.deletePreviousHistory = Optional.fromNullable(deletePreviousHistory).or(false);
this.deletePreviousHistory = Optional.ofNullable(deletePreviousHistory).orElse(false);
previousOutcomeConverter = new GsonPreviousOutcomeConverter(Injectors.getInjector().getInstance(EnvironmentVariables.class));
}

Expand Down Expand Up @@ -89,7 +88,9 @@ public List<PreviousTestOutcome> loadSummaries() {
if (Files.exists(historyDirectory)) {
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(historyDirectory)) {
for (Path path : directoryStream) {
previousTestOutcomes.addAll(previousTestOutcomesFrom(path).asSet());
previousTestOutcomesFrom(path).ifPresent(
outcome -> previousTestOutcomes.add(outcome)
);
}
} catch (IOException ex) {
LOGGER.warn("Unable to store test outcome for posterity", ex);
Expand All @@ -103,7 +104,7 @@ private Optional<PreviousTestOutcome> previousTestOutcomesFrom(Path source) {
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(source.toFile()))) {
return previousOutcomeConverter.fromJson(inputStream);
} catch (IOException e) {
return Optional.absent();
return Optional.empty();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.serenitybdd.core.pages;

import com.google.common.base.Optional;
import org.openqa.selenium.WebDriver;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;

public class PageObjects {

Expand Down Expand Up @@ -54,7 +54,7 @@ private <T extends PageObject> Optional<T> newPageObjectWithSimpleConstructor(Cl
} catch (NoSuchMethodException e) {
// Try a different constructor
}
return Optional.absent();
return Optional.empty();
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.core.pages;

import com.google.common.base.Optional;
import net.serenitybdd.core.environment.ConfiguredEnvironment;
import net.thucydides.core.annotations.DefaultUrl;
import net.thucydides.core.annotations.NamedUrl;
Expand All @@ -10,6 +9,7 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;

/**
* Manage the URLs associated with a page
Expand Down Expand Up @@ -50,9 +50,9 @@ public String getStartingUrl() {
private Optional<String> getDeclaredDefaultUrl() {
DefaultUrl urlAnnotation = pageObject.getClass().getAnnotation(DefaultUrl.class);
if (urlAnnotation != null) {
return Optional.fromNullable(urlAnnotation.value());
return Optional.ofNullable(urlAnnotation.value());
} else {
return Optional.absent();
return Optional.empty();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.core.pages;

import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import io.appium.java_client.*;
import net.serenitybdd.core.time.InternalSystemClock;
Expand All @@ -18,6 +17,7 @@
import net.thucydides.core.webdriver.stubs.WebElementFacadeStub;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.interactions.internal.Locatable;
import org.openqa.selenium.remote.RemoteWebElement;
Expand All @@ -26,10 +26,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -1019,15 +1016,15 @@ public WebElementState expect(String errorMessage) {
return copy().expectingErrorMessage(errorMessage);
}

private Optional<String> expectedErrorMessage = Optional.absent();
private Optional<String> expectedErrorMessage = Optional.empty();

protected WebElementState expectingErrorMessage(String errorMessage) {
this.expectedErrorMessage = Optional.of(errorMessage);
return this;
}

protected String getErrorMessage(String defaultErrorMessage) {
return expectedErrorMessage.or(defaultErrorMessage);
return expectedErrorMessage.orElse(defaultErrorMessage);
}

private boolean valueAttributeSupportedAndDefinedIn(final WebElement element) {
Expand Down Expand Up @@ -1116,7 +1113,7 @@ private Optional<WebDriverFacade> webDriverFacade() {
if (driver instanceof WebElementFacade) {
return Optional.of((WebDriverFacade) driver);
} else {
return Optional.absent();
return Optional.empty();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.serenitybdd.core.photography;

import com.google.common.base.Optional;
import org.openqa.selenium.WebDriver;

import java.io.File;
import java.nio.file.Path;
import java.util.Optional;

public class DisabledPageSourceRecorder extends PageSourceRecorder {
public DisabledPageSourceRecorder(WebDriver driver) {
Expand All @@ -13,6 +13,6 @@ public DisabledPageSourceRecorder(WebDriver driver) {

@Override
public Optional<File> intoDirectory(Path path) {
return Optional.absent();
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.serenitybdd.core.photography;


import com.google.common.base.Optional;
import net.thucydides.core.webdriver.WebDriverFactory;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
Expand All @@ -12,6 +11,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

public class PageSourceRecorder {
private final WebDriver driver;
Expand All @@ -33,7 +33,7 @@ public Optional<File> intoDirectory(Path path) {
LOGGER.warn("Could not save the page source HTML file", couldNotCreatePageSourcce);
}
}
return Optional.absent();
return Optional.empty();
}

private byte[] getPageSource() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.serenitybdd.core.photography;

import com.google.common.base.Optional;
import net.thucydides.core.screenshots.BlurLevel;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

public class ScreenshotNegative {
private final Path temporaryPath;
Expand All @@ -15,7 +15,7 @@ public class ScreenshotNegative {
public ScreenshotNegative(Path temporaryPath, Path screenshotPath, BlurLevel blurLevel) {
this.temporaryPath = temporaryPath;
this.screenshotPath = screenshotPath;
this.blurLevel = Optional.fromNullable(blurLevel).or(BlurLevel.NONE);
this.blurLevel = Optional.ofNullable(blurLevel).orElse(BlurLevel.NONE);
}

public Path getTemporaryPath() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package net.serenitybdd.core.photography;

import com.google.common.base.Optional;
import net.thucydides.core.model.TestResult;
import org.openqa.selenium.WebDriver;

import java.io.File;

public class SoundEngineer {

private boolean recordPageSource = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.serenitybdd.core.rest;

import com.google.common.base.Optional;
import java.util.Optional;

public enum RestMethod {
PUT,
Expand All @@ -11,10 +11,10 @@ public enum RestMethod {
HEAD,
DELETE;

private static final Optional<RestMethod> NOT_A_REST_METHOD = Optional.absent();
private static final Optional<RestMethod> NOT_A_REST_METHOD = Optional.empty();

public static Optional<RestMethod> restMethodCalled(String value) {
return isRestMethod(value) ? Optional.fromNullable(RestMethod.valueOf(value.toUpperCase())) : NOT_A_REST_METHOD;
return isRestMethod(value) ? Optional.ofNullable(RestMethod.valueOf(value.toUpperCase())) : NOT_A_REST_METHOD;
}

private static boolean isRestMethod(String value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package net.serenitybdd.core.rest;

import com.google.common.base.Optional;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public class RestQuery {

Expand All @@ -26,8 +25,8 @@ private RestQuery(RestMethod method, String path, List<Object> parameters, Map<S
String requestHeaders, String requestCookies, String responseHeaders, String responseCookies) {
this.method = method;
this.path = path;
this.parameters = Optional.fromNullable(parameters);
this.parameterMap = Optional.fromNullable(parameterMap);
this.parameters = Optional.ofNullable(parameters);
this.parameterMap = Optional.ofNullable(parameterMap);
this.content = content;
this.contentType = contentType;
this.responseBody = responseBody;
Expand Down Expand Up @@ -55,41 +54,41 @@ public RestQuery withParameters( Map<String, ?> parameterMap) {
}

public RestQuery withResponse(String responseBody) {
return new RestQuery(method, path, parameters.orNull(), parameterMap.orNull(), content, contentType,
return new RestQuery(method, path, parameters.orElse(null), parameterMap.orElse(null), content, contentType,
responseBody, statusCode, requestHeaders, requestCookies, responseHeaders, responseCookies);
}

public RestQuery withStatusCode(Integer statusCode) {
return new RestQuery(method, path, parameters.orNull(), parameterMap.orNull(), content, contentType,
return new RestQuery(method, path, parameters.orElse(null), parameterMap.orElse(null), content, contentType,
responseBody, statusCode, requestHeaders, requestCookies, responseHeaders, responseCookies);
}

public RestQuery withContent(String content) {
return new RestQuery(method, path, parameters.orNull(), parameterMap.orNull(), content, contentType,
return new RestQuery(method, path, parameters.orElse(null), parameterMap.orElse(null), content, contentType,
responseBody, statusCode, requestHeaders, requestCookies, responseHeaders, responseCookies);
}

public RestQuery withContentType(String contentType) {
return new RestQuery(method, path, parameters.orNull(), parameterMap.orNull(), content, contentType,
return new RestQuery(method, path, parameters.orElse(null), parameterMap.orElse(null), content, contentType,
responseBody, statusCode, requestHeaders, requestCookies, responseHeaders, responseCookies);
}

public RestQuery withResponseCookies(String responseCookies) {
return new RestQuery(method, path, parameters.orNull(), parameterMap.orNull(), content, contentType,
return new RestQuery(method, path, parameters.orElse(null), parameterMap.orElse(null), content, contentType,
responseBody, statusCode, requestHeaders, requestCookies, responseHeaders, responseCookies);
}

public RestQuery withResponseHeaders(String responseHeaders) {
return new RestQuery(method, path, parameters.orNull(), parameterMap.orNull(), content, contentType,
return new RestQuery(method, path, parameters.orElse(null), parameterMap.orElse(null), content, contentType,
responseBody, statusCode, requestHeaders, requestCookies, responseHeaders, responseCookies);
}
public RestQuery withRequestCookies(String requestCookies) {
return new RestQuery(method, path, parameters.orNull(), parameterMap.orNull(), content, contentType,
return new RestQuery(method, path, parameters.orElse(null), parameterMap.orElse(null), content, contentType,
responseBody, statusCode, requestHeaders, requestCookies, responseHeaders, responseCookies);
}

public RestQuery withRequestHeaders(String requestHeaders) {
return new RestQuery(method, path, parameters.orNull(), parameterMap.orNull(), content, contentType,
return new RestQuery(method, path, parameters.orElse(null), parameterMap.orElse(null), content, contentType,
responseBody, statusCode, requestHeaders, requestCookies, responseHeaders, responseCookies);
}

Expand Down
Loading

0 comments on commit a05f7e6

Please sign in to comment.