Skip to content

Commit

Permalink
Upgrade to latest Java-Utils; eliminate Guava usage (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbabcoc authored Jun 1, 2024
1 parent bbc81e8 commit 9cca930
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 47 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>8</maven.compiler.release>
<java-utils.version>3.1.1</java-utils.version>
<java-utils.version>3.2.0</java-utils.version>
<settings.version>3.0.5</settings.version>
<junit.version>4.13.2</junit.version>
<testng.version>7.5</testng.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

import org.junit.runner.Description;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.nordstrom.common.file.PathUtils;

/**
Expand Down Expand Up @@ -68,12 +68,12 @@ public void failed(Throwable e, Description description) {
*/
public Optional<Path> captureArtifact(Throwable reason) {
if (! provider.canGetArtifact(getInstance())) {
return Optional.absent();
return Optional.empty();
}

byte[] artifact = provider.getArtifact(getInstance(), reason);
if ((artifact == null) || (artifact.length == 0)) {
return Optional.absent();
return Optional.empty();
}

Path collectionPath = getCollectionPath();
Expand All @@ -85,7 +85,7 @@ public Optional<Path> captureArtifact(Throwable reason) {
String messageTemplate = "Unable to create collection directory ({}); no artifact was captured";
provider.getLogger().warn(messageTemplate, collectionPath, e);
}
return Optional.absent();
return Optional.empty();
}
}

Expand All @@ -99,7 +99,7 @@ public Optional<Path> captureArtifact(Throwable reason) {
if (provider.getLogger() != null) {
provider.getLogger().warn("Unable to get output path; no artifact was captured", e);
}
return Optional.absent();
return Optional.empty();
}

try {
Expand All @@ -111,7 +111,7 @@ public Optional<Path> captureArtifact(Throwable reason) {
if (provider.getLogger() != null) {
provider.getLogger().warn("I/O error saving to ({}); no artifact was captured", artifactPath, e);
}
return Optional.absent();
return Optional.empty();
}

recordArtifactPath(artifactPath);
Expand Down Expand Up @@ -163,7 +163,7 @@ private void recordArtifactPath(Path artifactPath) {
*/
public Optional<List<Path>> retrieveArtifactPaths() {
if (artifactPaths.isEmpty()) {
return Optional.absent();
return Optional.empty();
} else {
return Optional.of(artifactPaths);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public T getArtifactProvider() {
}
}
}
return Optional.absent();
return Optional.empty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.nordstrom.automation.junit;

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

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

import com.google.common.base.Optional;

/**
* This is the base class for test watchers that need access to the test class instance for the current atomic test.
* For test classes that implement the {@link ArtifactParams} interface, instance parameters can be retrieved via the
Expand Down Expand Up @@ -63,7 +62,7 @@ public Optional<Map<String, Object>> getParameters() {
if (instance instanceof ArtifactParams) {
return ((ArtifactParams) instance).getParameters();
}
return Optional.absent();
return Optional.empty();
}

}
3 changes: 1 addition & 2 deletions src/main/java/com/nordstrom/automation/junit/CreateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;

import org.junit.runners.model.FrameworkMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Function;

import net.bytebuddy.implementation.bind.annotation.Argument;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;

import org.apache.commons.lang3.reflect.MethodUtils;
import org.junit.internal.runners.model.ReflectiveCallable;
import org.junit.runner.Description;
import org.junit.runner.notification.RunListener;
import org.junit.runners.model.TestClass;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.nordstrom.common.base.UncheckedThrow;
import com.nordstrom.common.file.PathUtils.ReportsDirectory;

Expand Down Expand Up @@ -418,7 +418,7 @@ public static <T extends JUnitWatcher> Optional<T> getAttachedWatcher(Class<T> w
return Optional.of((T) watcher);
}
}
return Optional.absent();
return Optional.empty();
}

/**
Expand Down Expand Up @@ -481,7 +481,7 @@ private static <T extends RunListener> Optional<T> findListener(Class<T> type, L
return Optional.of((T) listener);
}
}
return Optional.absent();
return Optional.empty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;

import org.junit.experimental.theories.Theories.TheoryAnchor;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import com.google.common.base.Function;

import net.bytebuddy.implementation.bind.annotation.SuperCall;
import net.bytebuddy.implementation.bind.annotation.This;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.lang.reflect.Field;
import java.util.List;
import java.util.Optional;

import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

import com.google.common.base.Optional;
import com.nordstrom.common.base.UncheckedThrow;

/**
Expand Down Expand Up @@ -38,7 +38,7 @@ public static <T extends TestRule> Optional<T> getAttachedRule(RuleChain ruleCha
return Optional.of((T) rule);
}
}
return Optional.absent();
return Optional.empty();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/nordstrom/automation/junit/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.Function;

import org.junit.runner.Description;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Function;

import net.bytebuddy.implementation.bind.annotation.Argument;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
import net.bytebuddy.implementation.bind.annotation.This;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;

import org.junit.internal.runners.model.ReflectiveCallable;
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Function;
import com.nordstrom.common.base.UncheckedThrow;

import net.bytebuddy.implementation.bind.annotation.RuntimeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import static org.junit.Assert.assertEquals;

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

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.internal.runners.model.ReflectiveCallable;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;

import com.google.common.base.Optional;

@RunWith(JUnitParamsRunner.class)
public class ArtifactCollectorJUnitParams extends TestBase {

Expand Down Expand Up @@ -44,7 +43,7 @@ public Optional<Map<String, Object>> getParameters() {
// return params map as Optional
return Param.mapOf(namedParams);
} catch (IllegalAccessException | NoSuchFieldException e) {
return Optional.absent();
return Optional.empty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import static org.junit.Assert.assertEquals;

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

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import com.google.common.base.Optional;

@RunWith(Parameterized.class)
public class ArtifactCollectorParameterized extends TestBase {

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

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
Expand All @@ -16,7 +17,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.google.common.base.Optional;
import com.nordstrom.automation.junit.JUnitConfig.JUnitSettings;
import com.nordstrom.automation.junit.UnitTestArtifact.CaptureState;
import com.nordstrom.automation.junit.UnitTestWatcher.Notification;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import static org.junit.Assert.assertEquals;

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

import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.PotentialAssignment.CouldNotGenerateValueException;
import org.junit.experimental.theories.internal.Assignments;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import com.google.common.base.Optional;

@RunWith(Theories.class)
public class ArtifactCollectorTheories extends TestBase {
Expand Down Expand Up @@ -39,7 +39,7 @@ public Optional<Map<String, Object>> getParameters() {
// return params map as Optional
return Param.mapOf(namedParams);
} catch (IllegalAccessException | NoSuchFieldException | CouldNotGenerateValueException e) {
return Optional.absent();
return Optional.empty();
}
}

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

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.google.common.base.Optional;
import com.nordstrom.automation.junit.JUnitConfig.JUnitSettings;
import com.nordstrom.automation.junit.UnitTestWatcher.Notification;

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

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.testng.annotations.Test;

import com.google.common.base.Optional;
import com.nordstrom.automation.junit.UnitTestWatcher.Notification;

public class BeforeClassFailureTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import static org.testng.Assert.assertTrue;

import java.util.Optional;

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.testng.annotations.Test;

import com.google.common.base.Optional;

public class HookInstallationTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nordstrom.automation.junit;

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

public class ReferenceTracker implements RunnerWatcher {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;

import com.google.common.base.Optional;

/**
* This run listener tracks the results of executed tests.
*/
Expand Down
Loading

0 comments on commit 9cca930

Please sign in to comment.