diff --git a/.infra/checkstyle/checkstyle.xml b/.infra/checkstyle/checkstyle.xml
index 857c7db70..1b5834f10 100644
--- a/.infra/checkstyle/checkstyle.xml
+++ b/.infra/checkstyle/checkstyle.xml
@@ -23,6 +23,10 @@
+
+
+
+
diff --git a/build.gradle.kts b/build.gradle.kts
index 3b986d958..d9c1cdf99 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -225,8 +225,6 @@ tasks {
// See https://docs.gradle.org/current/userguide/java_testing.html#sec:java_testing_modular_patching
val patchModuleArg = "--patch-module=$moduleName=${compileJava.get().destinationDirectory.asFile.get().path}"
val testJvmArgs = listOf(
- // Ignore these options on Java 8
- "-XX:+IgnoreUnrecognizedVMOptions",
// EnvironmentVariableUtils: make java.util.Map accessible
"--add-opens=java.base/java.util=$moduleName",
// EnvironmentVariableUtils: make java.lang.System accessible
@@ -301,7 +299,6 @@ tasks {
filter {
includeTestsMatching("*Demo")
}
- jvmArgs(testJvmArgs)
}
}
}
diff --git a/src/demo/java/org/junitpioneer/vintage/VintageTestDemo.java b/src/demo/java/org/junitpioneer/vintage/VintageTestDemo.java
index 29f6574a5..8ae4aa2c5 100644
--- a/src/demo/java/org/junitpioneer/vintage/VintageTestDemo.java
+++ b/src/demo/java/org/junitpioneer/vintage/VintageTestDemo.java
@@ -10,21 +10,21 @@
package org.junitpioneer.vintage;
-import java.util.ArrayList;
+import java.util.List;
public class VintageTestDemo {
// tag::vintage_test_indexoutofbound_exception[]
@Test(expected = IndexOutOfBoundsException.class)
public void outOfBounds_passes() {
- new ArrayList().get(1);
+ List.of().get(1);
}
// end::vintage_test_indexoutofbound_exception[]
// tag::vintage_test_runtime_exception[]
@Test(expected = RuntimeException.class)
public void outOfBounds_passes_too() {
- new ArrayList().get(1);
+ List.of().get(1);
}
// end::vintage_test_runtime_exception[]
@@ -33,7 +33,7 @@ class TheseTestsWillFailIntentionally {
// tag::vintage_test_iae_exception[]
@Test(expected = IllegalArgumentException.class)
public void outOfBounds_fails() {
- new ArrayList().get(1);
+ List.of().get(1);
}
// end::vintage_test_iae_exception[]
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 3a47826af..0b19d73f3 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -4,10 +4,10 @@
*
* Pioneer does not limit itself to proven ideas with wide application but is purposely open to
* experimentation. It aims to spin off successful and cohesive portions into sibling projects or back
- * into the JUnit 5 code base.
+ * into the JUnit 5 code base.
*
* The dependencies on Jupiter modules could be marked as transitive
but that would
- * allow users who depend on this module to not `require` org.junit.*, which would be backwards.
+ * allow users who depend on this module to not `require` org.junit.*, which would be backwards.
*/
module org.junitpioneer {
// see Javadoc for why these aren't transitive
diff --git a/src/main/java/org/junitpioneer/internal/PioneerAnnotationUtils.java b/src/main/java/org/junitpioneer/internal/PioneerAnnotationUtils.java
index 171f29369..c148d59ff 100644
--- a/src/main/java/org/junitpioneer/internal/PioneerAnnotationUtils.java
+++ b/src/main/java/org/junitpioneer/internal/PioneerAnnotationUtils.java
@@ -10,6 +10,9 @@
package org.junitpioneer.internal;
+import static java.util.function.Predicate.not;
+import static java.util.stream.Collectors.toUnmodifiableList;
+
import java.lang.annotation.Annotation;
import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;
@@ -20,10 +23,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.extension.ExtensionContext;
@@ -34,9 +35,9 @@
/**
* Pioneer-internal utility class to handle annotations.
* DO NOT USE THIS CLASS - IT MAY CHANGE SIGNIFICANTLY IN ANY MINOR UPDATE.
- *
+ *
* It uses the following terminology to describe annotations that are not
- * immediately present on an element:
+ * immediately present on an element:
*
*
* indirectly present if a supertype of the element is annotated
@@ -45,9 +46,11 @@
* {@link org.junit.jupiter.api.Nested @Nested}) is annotated
*
*
+ *
* All of the above mechanisms apply recursively, meaning that, e.g., for an annotation to be
* meta-present it can present on an annotation that is present on another annotation
* that is present on the element.
+ *
*/
public class PioneerAnnotationUtils {
@@ -133,7 +136,7 @@ public static List findAnnotatedAnnotations(A
// flatten @Repeatable aggregator annotations
.flatMap(PioneerAnnotationUtils::flatten)
.filter(a -> !(findOnType(a.annotationType(), annotation, isRepeatable, false).isEmpty()))
- .collect(Collectors.toList());
+ .collect(toUnmodifiableList());
}
private static Stream flatten(Annotation annotation) {
@@ -183,7 +186,7 @@ static Stream findAnnotations(ExtensionContext context
List onMethod = context
.getTestMethod()
.map(method -> findOnMethod(method, annotationType, findRepeated))
- .orElse(Collections.emptyList());
+ .orElse(List.of());
if (!findAllEnclosing && !onMethod.isEmpty())
return onMethod.stream();
Stream onClass = findOnOuterClasses(context.getTestClass(), annotationType, findRepeated, findAllEnclosing);
@@ -196,15 +199,12 @@ private static List findOnMethod(Method element, Class
if (findRepeated)
return AnnotationSupport.findRepeatableAnnotations(element, annotationType);
else
- return AnnotationSupport
- .findAnnotation(element, annotationType)
- .map(Collections::singletonList)
- .orElse(Collections.emptyList());
+ return AnnotationSupport.findAnnotation(element, annotationType).stream().collect(toUnmodifiableList());
}
private static Stream findOnOuterClasses(Optional> type, Class annotationType,
boolean findRepeated, boolean findAllEnclosing) {
- if (!type.isPresent())
+ if (type.isEmpty())
return Stream.empty();
List onThisClass = Arrays.asList(type.get().getAnnotationsByType(annotationType));
@@ -220,18 +220,18 @@ private static Stream findOnOuterClasses(Optional List findOnType(Class> element, Class annotationType,
boolean findRepeated, boolean findAllEnclosing) {
if (element == null || element == Object.class)
- return Collections.emptyList();
+ return List.of();
if (findRepeated)
return AnnotationSupport.findRepeatableAnnotations(element, annotationType);
List onElement = AnnotationSupport
.findAnnotation(element, annotationType)
- .map(Collections::singletonList)
- .orElse(Collections.emptyList());
+ .stream()
+ .collect(toUnmodifiableList());
List onInterfaces = Arrays
.stream(element.getInterfaces())
.flatMap(clazz -> findOnType(clazz, annotationType, false, findAllEnclosing).stream())
- .collect(Collectors.toList());
+ .collect(toUnmodifiableList());
if (!annotationType.isAnnotationPresent(Inherited.class)) {
if (!findAllEnclosing)
return onElement;
@@ -240,23 +240,23 @@ private static List findOnType(Class> element, Class
.of(onElement, onInterfaces)
.flatMap(Collection::stream)
.distinct()
- .collect(Collectors.toList());
+ .collect(toUnmodifiableList());
}
List onSuperclass = findOnType(element.getSuperclass(), annotationType, false, findAllEnclosing);
return Stream
.of(onElement, onInterfaces, onSuperclass)
.flatMap(Collection::stream)
.distinct()
- .collect(Collectors.toList());
+ .collect(toUnmodifiableList());
}
public static List findParameterArgumentsSources(Method testMethod) {
return Arrays
.stream(testMethod.getParameters())
.map(PioneerAnnotationUtils::collectArgumentSources)
- .filter(list -> !list.isEmpty())
+ .filter(not(List::isEmpty))
.map(annotations -> annotations.get(0))
- .collect(Collectors.toList());
+ .collect(toUnmodifiableList());
}
private static List collectArgumentSources(Parameter parameter) {
@@ -274,7 +274,7 @@ public static List findMethodArgumentsSources(Method testMethod) {
.filter(annotation -> AnnotationSupport
.findAnnotation(annotation.annotationType(), CartesianArgumentsSource.class)
.isPresent())
- .collect(Collectors.toList());
+ .collect(toUnmodifiableList());
}
}
diff --git a/src/main/java/org/junitpioneer/internal/PioneerPreconditions.java b/src/main/java/org/junitpioneer/internal/PioneerPreconditions.java
index 83c58b2f9..1d482c7f8 100644
--- a/src/main/java/org/junitpioneer/internal/PioneerPreconditions.java
+++ b/src/main/java/org/junitpioneer/internal/PioneerPreconditions.java
@@ -32,7 +32,7 @@ private PioneerPreconditions() {
* @return the supplied string
*/
public static String notBlank(String str, String message) {
- if (str == null || str.trim().isEmpty()) {
+ if (str == null || str.isBlank()) {
throw new PreconditionViolationException(message);
}
@@ -46,7 +46,7 @@ public static String notBlank(String str, String message) {
* @return the supplied string
*/
public static String notBlank(String str, Supplier messageSupplier) {
- if (str == null || str.trim().isEmpty()) {
+ if (str == null || str.isBlank()) {
throw new PreconditionViolationException(messageSupplier.get());
}
diff --git a/src/main/java/org/junitpioneer/internal/PioneerUtils.java b/src/main/java/org/junitpioneer/internal/PioneerUtils.java
index cbec47d1d..b1604e44d 100644
--- a/src/main/java/org/junitpioneer/internal/PioneerUtils.java
+++ b/src/main/java/org/junitpioneer/internal/PioneerUtils.java
@@ -16,14 +16,12 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collector;
-import java.util.stream.Collectors;
import org.junit.jupiter.api.extension.ExtensionContext;
@@ -40,7 +38,7 @@ private PioneerUtils() {
}
/**
- * A {@link Collectors#toSet() toSet} collector that throws an {@link IllegalStateException}
+ * A {@link java.util.stream.Collectors#toSet() toSet} collector that throws an {@link IllegalStateException}
* on duplicate elements (according to {@link Object#equals(Object) equals}).
*/
public static Collector, Set> distinctToSet() {
@@ -63,7 +61,7 @@ private static void addButThrowIfDuplicate(Set set, T element) {
* interface and traversing its enclosing classes until such a method is
* found or the top level class is reached.
*
- * The algorithm does not search for methods in {@link java.lang.Object}.
+ *
The algorithm does not search for methods in {@link java.lang.Object}.
*
* @param clazz the class or interface in which to find the method; never {@code null}
* @param methodName the name of the method to find; never {@code null} or empty
@@ -81,7 +79,7 @@ public static Optional findMethodCurrentOrEnclosing(Class> clazz, Stri
// null checking done by ReflectionSupport.findMethod
method = findMethod(current, methodName, parameterTypes);
current = current.getEnclosingClass();
- } while (!method.isPresent() && current != null);
+ } while (method.isEmpty() && current != null);
return method;
}
@@ -98,7 +96,7 @@ public static List findAllContexts(ExtensionContext context) {
List parentContexts = context
.getParent()
.map(PioneerUtils::findAllContexts)
- .orElse(Collections.emptyList());
+ .orElse(List.of());
allContexts.addAll(parentContexts);
return allContexts;
}
@@ -148,7 +146,7 @@ public static Class wrap(Class clazz) {
public static List> cartesianProduct(List> lists) {
List> resultLists = new ArrayList<>();
if (lists.isEmpty()) {
- resultLists.add(Collections.emptyList());
+ resultLists.add(List.of());
return resultLists;
}
List> firstList = lists.get(0);
diff --git a/src/main/java/org/junitpioneer/jupiter/DisableIfTestFails.java b/src/main/java/org/junitpioneer/jupiter/DisableIfTestFails.java
index cf458484e..18404a045 100644
--- a/src/main/java/org/junitpioneer/jupiter/DisableIfTestFails.java
+++ b/src/main/java/org/junitpioneer/jupiter/DisableIfTestFails.java
@@ -20,20 +20,23 @@
/**
* Disables all remaining tests in a container if one of them failed.
- *
+ *
* By default, all exceptions (including assertions, but exempting failed assumptions) will lead to
* disabling the remaining tests. To configure this in more detail, see {@link #with()} and
* {@link #onAssertion()}.
- *
+ *
+ *
* This annotation can be (meta-)present on classes that contain a nested class. In that case, a
* failing test in the outer class will disable the nested class (if it runs later) and vice versa.
- *
+ *
+ *
* This annotation can be (meta-)present on a class and/or its super types (classes or interfaces).
* In that case, the exception types given to {@link #with()} are merged and {@link #onAssertion()}
* is or'ed.
- *
+ *
+ *
* But if a test fails in a specific class, only other tests in the corresponding container will
- * be disabled. That means if...
+ * be disabled. That means if...
*
*
* a class {@code SpecificTests} implements interface {@code Tests} and
@@ -52,19 +55,21 @@
/**
* Configure on which exceptions remaining tests are disabled (defaults to "any exception").
- *
+ *
* If {@code @DisableIfTestFails} is present multiple times (e.g. on multiple super types),
* these exceptions are collected across all annotations, meaning if any of the mentioned
* exceptions are thrown, the remaining tests are disabled.
+ *
*/
Class extends Throwable>[] with() default {};
/**
* Set to {@code false} if failed assertions should not lead to disabling remaining tests.
- *
+ *
* If {@code @DisableIfTestFails} is present multiple times (e.g. on multiple super types),
* this value is or'ed, meaning as soon as one annotation says to fail on assertion errors,
* that's how the container will behave.
+ *
*/
boolean onAssertion() default true;
diff --git a/src/main/java/org/junitpioneer/jupiter/DisableIfTestFailsExtension.java b/src/main/java/org/junitpioneer/jupiter/DisableIfTestFailsExtension.java
index 36a2f9d08..0ee33819a 100644
--- a/src/main/java/org/junitpioneer/jupiter/DisableIfTestFailsExtension.java
+++ b/src/main/java/org/junitpioneer/jupiter/DisableIfTestFailsExtension.java
@@ -10,8 +10,8 @@
package org.junitpioneer.jupiter;
-import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Collectors.toUnmodifiableList;
import java.util.Arrays;
import java.util.List;
@@ -31,11 +31,11 @@ class DisableIfTestFailsExtension implements TestExecutionExceptionHandler, Exec
/*
* Basic approach:
- * - in `handleTestExecutionException`: if need to deactivate other tests, add that info to the store
+ * - in `handleTestExecutionException`: if it needs to deactivate other tests, add that info to the store
* - in `evaluateExecutionCondition`: check store for that information
*
* Because the test method that failed and the ones that need to be disabled are different methods,
- * the information to disable can't be in a store that belongs to any specific test method. Instead
+ * the information to disable can't be in a store that belongs to any specific test method. Instead,
* add it to the store that belongs to the container where the extension is applied.
*
* Setting the information needs to be thread safe, so only positive results (i.e. tests must be disabled)
@@ -72,17 +72,19 @@ public void handleTestExecutionException(ExtensionContext context, Throwable thr
private static Stream findConfigurations(ExtensionContext context) {
Optional> type = context.getTestClass();
// type may not be present because of recursion to the parent context
- if (!type.isPresent())
+ if (type.isEmpty())
return Stream.empty();
- List annotations = findAnnotationOn(type.get()).collect(toList());
+ List annotations = findAnnotationOn(type.get()).collect(toUnmodifiableList());
Stream onClassConfig = createConfigurationFor(context, annotations);
Stream onParentClassConfigs = context
.getParent()
.map(DisableIfTestFailsExtension::findConfigurations)
.orElse(Stream.empty());
- List configurations = Stream.concat(onClassConfig, onParentClassConfigs).collect(toList());
+ List configurations = Stream
+ .concat(onClassConfig, onParentClassConfigs)
+ .collect(toUnmodifiableList());
return configurations.stream();
}
@@ -112,9 +114,7 @@ private static Stream findAnnotationOn(Class> element) {
Stream onElement = AnnotationSupport
.findAnnotation(element, DisableIfTestFails.class)
- // turn Optional into Stream
- .map(Stream::of)
- .orElse(Stream.empty());
+ .stream();
Stream onInterfaces = Arrays
.stream(element.getInterfaces())
.flatMap(DisableIfTestFailsExtension::findAnnotationOn);
diff --git a/src/main/java/org/junitpioneer/jupiter/DisabledUntil.java b/src/main/java/org/junitpioneer/jupiter/DisabledUntil.java
index 21b8ffff0..12ac8bcb7 100644
--- a/src/main/java/org/junitpioneer/jupiter/DisabledUntil.java
+++ b/src/main/java/org/junitpioneer/jupiter/DisabledUntil.java
@@ -23,7 +23,7 @@
* essentially disabling a test temporarily. The date is given as an ISO 8601 string.
*
* It may optionally be declared with a reason to document why the annotated test class or test
- * method is disabled.
+ * method is disabled.
*
* {@code @DisabledUntil} can be used on the method and class level. It can only be used once per method or class,
* but is inherited from higher-level containers.
diff --git a/src/main/java/org/junitpioneer/jupiter/EnvironmentVariableUtils.java b/src/main/java/org/junitpioneer/jupiter/EnvironmentVariableUtils.java
index 1735c0d09..a3b77b50d 100644
--- a/src/main/java/org/junitpioneer/jupiter/EnvironmentVariableUtils.java
+++ b/src/main/java/org/junitpioneer/jupiter/EnvironmentVariableUtils.java
@@ -11,6 +11,7 @@
package org.junitpioneer.jupiter;
import java.lang.reflect.Field;
+import java.lang.reflect.InaccessibleObjectException;
import java.util.Map;
import java.util.function.Consumer;
@@ -98,15 +99,12 @@ private static Map getFieldValue(Class> clazz, Object object,
try {
field.setAccessible(true); //NOSONAR illegal access required to implement the extension
}
- catch (RuntimeException ex) {
- // Java 9 added InaccessibleObjectException, but we compile against Java 8.
- if (ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException"))
- throw new ExtensionConfigurationException(
- "Cannot access Java runtime internals to modify environment variables. "
- + "Have a look at the documentation for possible solutions: "
- + "https://junit-pioneer.org/docs/environment-variables/#warnings-for-reflective-access",
- ex);
- throw ex;
+ catch (InaccessibleObjectException ex) {
+ throw new ExtensionConfigurationException(
+ "Cannot access Java runtime internals to modify environment variables. "
+ + "Have a look at the documentation for possible solutions: "
+ + "https://junit-pioneer.org/docs/environment-variables/#warnings-for-reflective-access",
+ ex);
}
return (Map) field.get(object);
}
diff --git a/src/main/java/org/junitpioneer/jupiter/ExpectedToFail.java b/src/main/java/org/junitpioneer/jupiter/ExpectedToFail.java
index 7df0f60ff..2760633a7 100644
--- a/src/main/java/org/junitpioneer/jupiter/ExpectedToFail.java
+++ b/src/main/java/org/junitpioneer/jupiter/ExpectedToFail.java
@@ -31,16 +31,19 @@
* annotation is that the developer is informed as soon as a test is successful again.
* This helps to avoid creating duplicate tests by accident and counteracts the accumulation
* of disabled tests over time.
+ *
*
* The annotation can only be used on methods and as meta-annotation on other annotation types.
* Similar to {@code @Disabled}, it has to be used in addition to a "testable" annotation, such
* as {@link org.junit.jupiter.api.Test @Test}. Otherwise the annotation has no effect.
+ *
*
* Important: This annotation is not intended as a way to mark test methods
* which intentionally cause exceptions. Such test methods should use
* {@link org.junit.jupiter.api.Assertions#assertThrows(Class, org.junit.jupiter.api.function.Executable) assertThrows}
* or similar means to explicitly test for a specific exception class being thrown by a
* specific action.
+ *
*
* For more details and examples, see
* the documentation on @ExpectedToFail
.
diff --git a/src/main/java/org/junitpioneer/jupiter/ExpectedToFailExtension.java b/src/main/java/org/junitpioneer/jupiter/ExpectedToFailExtension.java
index ed1930661..54a844468 100644
--- a/src/main/java/org/junitpioneer/jupiter/ExpectedToFailExtension.java
+++ b/src/main/java/org/junitpioneer/jupiter/ExpectedToFailExtension.java
@@ -29,7 +29,7 @@ public void interceptTestMethod(Invocation invocation, ReflectiveInvocatio
invokeAndInvertResult(invocation, extensionContext);
}
- private static T invokeAndInvertResult(Invocation invocation, ExtensionContext extensionContext)
+ private static void invokeAndInvertResult(Invocation invocation, ExtensionContext extensionContext)
throws Throwable {
try {
invocation.proceed();
@@ -50,7 +50,7 @@ private static T invokeAndInvertResult(Invocation invocation, ExtensionCo
throw new TestAbortedException(message, t);
}
- return fail("Test marked as 'expected to fail' succeeded; remove @ExpectedToFail from it");
+ fail("Test marked as 'expected to fail' succeeded; remove @ExpectedToFail from it");
}
/**
@@ -59,11 +59,12 @@ private static T invokeAndInvertResult(Invocation invocation, ExtensionCo
*
* This method is used for exceptions that abort test execution and should
* have higher precedence than aborted exceptions thrown by this extension.
+ *
*/
private static boolean shouldPreserveException(Throwable t) {
// Note: Ideally would use the same logic JUnit uses to determine if exception is aborting
// execution, see its class OpenTest4JAndJUnit4AwareThrowableCollector
- return TestAbortedException.class.isInstance(t);
+ return t instanceof TestAbortedException;
}
private static ExpectedToFail getExpectedToFailAnnotation(ExtensionContext context) {
diff --git a/src/main/java/org/junitpioneer/jupiter/Issue.java b/src/main/java/org/junitpioneer/jupiter/Issue.java
index 1ffd6c971..ca8bc67ef 100644
--- a/src/main/java/org/junitpioneer/jupiter/Issue.java
+++ b/src/main/java/org/junitpioneer/jupiter/Issue.java
@@ -21,10 +21,11 @@
/**
* {@code @Issue} is a JUnit Jupiter extension to mark tests that
* exist to cover an issue, like a requirement or a bugfix.
- *
+ *
* The annotated issue ID will be published as a report entry - where
* this information will be visible, depends on the tool used to
* execute the tests.
+ *
*
* {@code @Issue} can be used on the method and class level.
* Warning: If you place it on class level, make sure to not mix tests which belong to the issue and those which don't!
diff --git a/src/main/java/org/junitpioneer/jupiter/IssueTestCase.java b/src/main/java/org/junitpioneer/jupiter/IssueTestCase.java
index d9c8591e8..41e70c024 100644
--- a/src/main/java/org/junitpioneer/jupiter/IssueTestCase.java
+++ b/src/main/java/org/junitpioneer/jupiter/IssueTestCase.java
@@ -18,8 +18,9 @@
/**
* Represents the execution result of test method, which is annotated with {@link Issue}.
- *
+ *
* Once Pioneer baselines against Java 17, this will be a record.
+ *
*
* @since 1.1
* @see Issue
@@ -52,9 +53,9 @@ public String testId() {
}
/**
- * Returns the result of the test methods execution.
+ * Returns the result of the test methods' execution.
*
- * @return Result of the test methods execution.
+ * @return Result of the test methods' execution.
*/
public Status result() {
return result;
diff --git a/src/main/java/org/junitpioneer/jupiter/IssueTestSuite.java b/src/main/java/org/junitpioneer/jupiter/IssueTestSuite.java
index c5ba2e22d..566693478 100644
--- a/src/main/java/org/junitpioneer/jupiter/IssueTestSuite.java
+++ b/src/main/java/org/junitpioneer/jupiter/IssueTestSuite.java
@@ -10,14 +10,14 @@
package org.junitpioneer.jupiter;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Represents the execution result of test method, which is annotated with {@link org.junitpioneer.jupiter.Issue}.
- *
+ *
* Once Pioneer baselines against Java 17, this will be a record.
+ *
*
* @since 1.1
* @see Issue
@@ -36,7 +36,7 @@ public final class IssueTestSuite {
*/
public IssueTestSuite(String issueId, List tests) {
this.issueId = issueId;
- this.tests = Collections.unmodifiableList(tests);
+ this.tests = List.copyOf(tests);
}
/**
diff --git a/src/main/java/org/junitpioneer/jupiter/ReportEntry.java b/src/main/java/org/junitpioneer/jupiter/ReportEntry.java
index 84f54b320..1102191ba 100644
--- a/src/main/java/org/junitpioneer/jupiter/ReportEntry.java
+++ b/src/main/java/org/junitpioneer/jupiter/ReportEntry.java
@@ -26,7 +26,7 @@
* {@link org.junit.jupiter.api.extension.ExtensionContext#publishReportEntry(String, String) ExtensionContext::publishReportEntry}
* from within the test method.
*
- * {@code ReportEntry} is repeatable and can be used on methods.
+ *
{@code ReportEntry} is repeatable and can be used on methods.
*
* This extension does not interact with
* parallel test execution .
diff --git a/src/main/java/org/junitpioneer/jupiter/RetryingTest.java b/src/main/java/org/junitpioneer/jupiter/RetryingTest.java
index b76d6eecf..c4cdb5108 100644
--- a/src/main/java/org/junitpioneer/jupiter/RetryingTest.java
+++ b/src/main/java/org/junitpioneer/jupiter/RetryingTest.java
@@ -102,7 +102,7 @@
*
*
Defaults to [{index}] {arguments}.
*
- * Supported placeholders:
+ *
Supported placeholders:
*
* - {@link org.junitpioneer.jupiter.RetryingTest#DISPLAY_NAME_PLACEHOLDER}
* - {@link org.junitpioneer.jupiter.RetryingTest#INDEX_PLACEHOLDER}
diff --git a/src/main/java/org/junitpioneer/jupiter/StdIo.java b/src/main/java/org/junitpioneer/jupiter/StdIo.java
index e77a6b9c2..d4d889613 100644
--- a/src/main/java/org/junitpioneer/jupiter/StdIo.java
+++ b/src/main/java/org/junitpioneer/jupiter/StdIo.java
@@ -22,10 +22,11 @@
* lines read from {@code System.in} (with parameter {@link StdIn}) or
* written to {@code System.out} (with parameter {@link StdOut StdOut}).
*
- * The annotated test method can have zero, one, or both parameters, but {@code StdIn} can only
+ * The annotated test method can have zero, one, or both parameters, but {@code StdIn} can only
* be provided if {@link StdIo#value()} is used to specify input - otherwise an
* {@link org.junit.jupiter.api.extension.ExtensionConfigurationException ExtensionConfigurationException}
* will be thrown.
+ *
*
* During
* parallel test execution ,
diff --git a/src/main/java/org/junitpioneer/jupiter/Stopwatch.java b/src/main/java/org/junitpioneer/jupiter/Stopwatch.java
index 7360f7ca2..f1612466e 100644
--- a/src/main/java/org/junitpioneer/jupiter/Stopwatch.java
+++ b/src/main/java/org/junitpioneer/jupiter/Stopwatch.java
@@ -22,7 +22,7 @@
* {@code @Stopwatch} is a JUnit Jupiter extension to measure the elapsed time of a test execution.
* It's based on the JUnit extension example.
*
- *
{@code Stopwatch} is not repeatable. It can be used on the method and class level.
+ *
{@code Stopwatch} is not repeatable. It can be used on the method and class level.
*
* @since 0.6
*/
diff --git a/src/main/java/org/junitpioneer/jupiter/cartesian/ArgumentSets.java b/src/main/java/org/junitpioneer/jupiter/cartesian/ArgumentSets.java
index 7f21c05b9..cba3790b0 100644
--- a/src/main/java/org/junitpioneer/jupiter/cartesian/ArgumentSets.java
+++ b/src/main/java/org/junitpioneer/jupiter/cartesian/ArgumentSets.java
@@ -10,7 +10,7 @@
package org.junitpioneer.jupiter.cartesian;
-import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toUnmodifiableList;
import java.util.ArrayList;
import java.util.Arrays;
@@ -100,7 +100,7 @@ public static ArgumentSets argumentsForFirstParameter(T... arguments) {
* @return a new {@link ArgumentSets} object
*/
public static ArgumentSets argumentsForFirstParameter(Stream arguments) {
- return new ArgumentSets(arguments.collect(toList()));
+ return new ArgumentSets(arguments.collect(toUnmodifiableList()));
}
/**
@@ -145,7 +145,7 @@ public final ArgumentSets argumentsForNextParameter(T... arguments) {
* @return this {@link ArgumentSets} object, for fluent set definitions
*/
public final ArgumentSets argumentsForNextParameter(Stream arguments) {
- return add(arguments.collect(toList()));
+ return add(arguments.collect(toUnmodifiableList()));
}
List> getArguments() {
diff --git a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianArgumentsSource.java b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianArgumentsSource.java
index 63a8abe24..c1301ec26 100644
--- a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianArgumentsSource.java
+++ b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianArgumentsSource.java
@@ -25,7 +25,7 @@
* {@code @CartesianArgumentsSource} may also be used as a meta-annotation in order to
* create a custom composed annotation that inherits the semantics
* of {@code @CartesianArgumentsSource}.
- *
+ *
* This annotation is used to provide arguments for a {@link CartesianTest}.
*
* @see CartesianTest
@@ -38,7 +38,6 @@
/**
* The type of {@link CartesianArgumentsProvider} to be used.
*/
- @SuppressWarnings("rawtypes")
Class extends CartesianArgumentsProvider> value();
}
diff --git a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianFactoryArgumentsProvider.java b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianFactoryArgumentsProvider.java
index d51bf11a2..0e1bc6a26 100644
--- a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianFactoryArgumentsProvider.java
+++ b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianFactoryArgumentsProvider.java
@@ -85,8 +85,7 @@ private static Class> findExplicitOrImplicitClass(Method testMethod, String me
}
private static boolean factoryMustBeStatic(Method factory, Object testInstance, TestInstance.Lifecycle lifecycle) {
- return testInstance == null || !factory.getDeclaringClass().isInstance(testInstance)
- || lifecycle != TestInstance.Lifecycle.PER_CLASS;
+ return !factory.getDeclaringClass().isInstance(testInstance) || lifecycle != TestInstance.Lifecycle.PER_CLASS;
}
private ArgumentSets invokeMethodFactory(Method testMethod, Method factory, Object testInstance) {
diff --git a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianMethodArgumentsProvider.java b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianMethodArgumentsProvider.java
index daa96764a..64bcb754d 100644
--- a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianMethodArgumentsProvider.java
+++ b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianMethodArgumentsProvider.java
@@ -14,9 +14,10 @@
/**
* Provides arguments for all parameters of a {@link CartesianTest} method.
- *
+ *
* For more information, see
* the Cartesian product documentation .
+ *
*/
public interface CartesianMethodArgumentsProvider extends CartesianArgumentsProvider {
diff --git a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianParameterArgumentsProvider.java b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianParameterArgumentsProvider.java
index 2ef042523..b3ab28fb5 100644
--- a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianParameterArgumentsProvider.java
+++ b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianParameterArgumentsProvider.java
@@ -17,9 +17,10 @@
/**
* Provides arguments for a single parameter of a {@link CartesianTest} method.
- *
+ *
* For more information, see
* the Cartesian product documentation .
+ *
*/
public interface CartesianParameterArgumentsProvider extends CartesianArgumentsProvider {
diff --git a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTestExtension.java b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTestExtension.java
index 6077ffc27..02e0413ee 100644
--- a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTestExtension.java
+++ b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTestExtension.java
@@ -11,7 +11,7 @@
package org.junitpioneer.jupiter.cartesian;
import static java.lang.String.format;
-import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toUnmodifiableList;
import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;
import static org.junitpioneer.internal.PioneerUtils.cartesianProduct;
@@ -164,7 +164,7 @@ private List> provideArguments(ExtensionContext context, Parameter source,
// We like to keep arguments in the order in which they were listed
// in the annotation. Could use a set with defined iteration, but
// this is more explicit.
- .collect(toList());
+ .collect(toUnmodifiableList());
}
}
diff --git a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTestInvocationContext.java b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTestInvocationContext.java
index e4c2ecd4e..e4a561b09 100644
--- a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTestInvocationContext.java
+++ b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTestInvocationContext.java
@@ -10,7 +10,6 @@
package org.junitpioneer.jupiter.cartesian;
-import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.extension.Extension;
@@ -34,7 +33,7 @@ public String getDisplayName(int invocationIndex) {
@Override
public List getAdditionalExtensions() {
- return Collections.singletonList(new CartesianProductResolver(parameters));
+ return List.of(new CartesianProductResolver(parameters));
}
}
diff --git a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianValueArgumentsProvider.java b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianValueArgumentsProvider.java
index f1a1e6167..7e6bef5ec 100644
--- a/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianValueArgumentsProvider.java
+++ b/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianValueArgumentsProvider.java
@@ -10,7 +10,7 @@
package org.junitpioneer.jupiter.cartesian;
-import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toUnmodifiableList;
import java.lang.reflect.Array;
import java.lang.reflect.Parameter;
@@ -51,7 +51,7 @@ Stream. of(
source.classes()
)
.filter(array -> Array.getLength(array) > 0)
- .collect(toList());
+ .collect(toUnmodifiableList());
// @formatter:on
if (arrays.size() != 1)
diff --git a/src/main/java/org/junitpioneer/jupiter/issue/IssueExtensionExecutionListener.java b/src/main/java/org/junitpioneer/jupiter/issue/IssueExtensionExecutionListener.java
index 9f519ccd6..a25eedaf7 100644
--- a/src/main/java/org/junitpioneer/jupiter/issue/IssueExtensionExecutionListener.java
+++ b/src/main/java/org/junitpioneer/jupiter/issue/IssueExtensionExecutionListener.java
@@ -10,18 +10,16 @@
package org.junitpioneer.jupiter.issue;
-import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toUnmodifiableList;
import static org.junit.platform.engine.TestExecutionResult.Status;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Stream;
import org.junit.platform.engine.TestExecutionResult;
import org.junit.platform.engine.reporting.ReportEntry;
@@ -29,6 +27,7 @@
import org.junit.platform.launcher.TestIdentifier;
import org.junit.platform.launcher.TestPlan;
import org.junitpioneer.jupiter.IssueProcessor;
+import org.junitpioneer.jupiter.IssueTestCase;
import org.junitpioneer.jupiter.IssueTestSuite;
/**
@@ -95,24 +94,22 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
}
List createIssueTestSuites() {
- //@formatter:off
- List suites = testCases
- .values().stream()
- .collect(toMap(IssueTestCaseBuilder::getIssueId, builder -> new ArrayList<>(Arrays.asList(builder)),
- (builders1, builders2) -> {
- builders1.addAll(builders2);
- return builders1;
- }))
- .entrySet().stream()
- .map(issueIdWithTestCases -> new IssueTestSuite(
- issueIdWithTestCases.getKey(),
- issueIdWithTestCases
- .getValue().stream()
- .map(IssueTestCaseBuilder::build)
- .collect(toList())))
- .collect(toList());
- //@formatter:on
- return Collections.unmodifiableList(suites);
+ return testCases
+ .values()
+ .stream()
+ .collect(toMap(IssueTestCaseBuilder::getIssueId, this::getIssueTestCases, this::mergeIssueTestCases))
+ .entrySet()
+ .stream()
+ .map(entry -> new IssueTestSuite(entry.getKey(), entry.getValue()))
+ .collect(toUnmodifiableList());
+ }
+
+ private List getIssueTestCases(IssueTestCaseBuilder builder) {
+ return List.of(builder.build());
+ }
+
+ private List mergeIssueTestCases(List first, List second) {
+ return Stream.concat(first.stream(), second.stream()).collect(toUnmodifiableList());
}
}
diff --git a/src/main/java/org/junitpioneer/jupiter/json/JsonClasspathSourceArgumentsProvider.java b/src/main/java/org/junitpioneer/jupiter/json/JsonClasspathSourceArgumentsProvider.java
index 5b141c47b..ba99e53a1 100644
--- a/src/main/java/org/junitpioneer/jupiter/json/JsonClasspathSourceArgumentsProvider.java
+++ b/src/main/java/org/junitpioneer/jupiter/json/JsonClasspathSourceArgumentsProvider.java
@@ -10,9 +10,10 @@
package org.junitpioneer.jupiter.json;
+import static java.util.stream.Collectors.toUnmodifiableList;
+
import java.io.InputStream;
import java.util.Arrays;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junitpioneer.internal.PioneerPreconditions;
@@ -30,7 +31,7 @@ public void accept(JsonClasspathSource jsonSource) {
.stream(jsonSource.value())
.map(JsonClasspathSourceArgumentsProvider::classpathResource);
- accept(resources.collect(Collectors.toList()), jsonSource.data());
+ accept(resources.collect(toUnmodifiableList()), jsonSource.data());
}
private static Source classpathResource(String resource) {
diff --git a/src/main/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProvider.java b/src/main/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProvider.java
index f4b7f9f4e..723165d2b 100644
--- a/src/main/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProvider.java
+++ b/src/main/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProvider.java
@@ -10,13 +10,14 @@
package org.junitpioneer.jupiter.json;
+import static java.util.stream.Collectors.toUnmodifiableList;
+
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.platform.commons.PreconditionViolationException;
@@ -32,7 +33,7 @@ class JsonFileSourceArgumentsProvider extends AbstractJsonSourceBasedArgumentsPr
@Override
public void accept(JsonFileSource jsonSource) {
Stream files = Arrays.stream(jsonSource.value()).map(JsonFileSourceArgumentsProvider::fileResource);
- accept(files.collect(Collectors.toList()), jsonSource.data());
+ accept(files.collect(toUnmodifiableList()), jsonSource.data());
}
private static Source fileResource(String file) {
diff --git a/src/main/java/org/junitpioneer/jupiter/json/JsonSource.java b/src/main/java/org/junitpioneer/jupiter/json/JsonSource.java
index a0ae5ca1b..30205baf7 100644
--- a/src/main/java/org/junitpioneer/jupiter/json/JsonSource.java
+++ b/src/main/java/org/junitpioneer/jupiter/json/JsonSource.java
@@ -53,6 +53,7 @@
* The JSON values to use as the source of arguments; must not be empty.
*
* Each value can represent a single object, or a collection of objects.
+ *
*/
String[] value();
diff --git a/src/main/java/org/junitpioneer/jupiter/json/Property.java b/src/main/java/org/junitpioneer/jupiter/json/Property.java
index 9a4b325d3..3369bafb4 100644
--- a/src/main/java/org/junitpioneer/jupiter/json/Property.java
+++ b/src/main/java/org/junitpioneer/jupiter/json/Property.java
@@ -18,9 +18,10 @@
/**
* An annotation indicating the name of the JSON property that should be extracted into the method parameter.
- *
+ *
* If the test code is compiled with the {@code -parameters} flag, and the test method parameter's name
* matches the JSON property's name, this annotation is not needed.
+ *
*
* @since 1.7.0
*/
diff --git a/src/main/java/org/junitpioneer/jupiter/json/package-info.java b/src/main/java/org/junitpioneer/jupiter/json/package-info.java
index 295de7708..e7c28284b 100644
--- a/src/main/java/org/junitpioneer/jupiter/json/package-info.java
+++ b/src/main/java/org/junitpioneer/jupiter/json/package-info.java
@@ -7,12 +7,13 @@
* the documentation on JSON tests
*
*
- * Check out the following types for details on providing values for parameterized tests:
+ *
Check out the following types for details on providing values for parameterized tests:
*
* {@link org.junitpioneer.jupiter.json.JsonSource}
* {@link org.junitpioneer.jupiter.json.JsonClasspathSource}
* {@link org.junitpioneer.jupiter.json.JsonFileSource}
*
+ *
*/
package org.junitpioneer.jupiter.json;
diff --git a/src/main/java/org/junitpioneer/jupiter/package-info.java b/src/main/java/org/junitpioneer/jupiter/package-info.java
index ee19ff490..52dc1b874 100644
--- a/src/main/java/org/junitpioneer/jupiter/package-info.java
+++ b/src/main/java/org/junitpioneer/jupiter/package-info.java
@@ -1,7 +1,8 @@
/**
* Extensions to the JUnit Jupiter engine.
*
- * Check out the following types for details:
+ *
Check out the following types for details:
+ *
*
* {@link org.junitpioneer.jupiter.ClearEnvironmentVariable} and {@link org.junitpioneer.jupiter.SetEnvironmentVariable}
* {@link org.junitpioneer.jupiter.ClearSystemProperty} and {@link org.junitpioneer.jupiter.SetSystemProperty}
@@ -15,7 +16,9 @@
* {@link org.junitpioneer.jupiter.Stopwatch}
*
*
+ *
* Also check the following packages:
+ *
*
* {@link org.junitpioneer.jupiter.cartesian cartesian}
* {@link org.junitpioneer.jupiter.issue issue}
diff --git a/src/main/java/org/junitpioneer/jupiter/params/DisableIfArgumentExtension.java b/src/main/java/org/junitpioneer/jupiter/params/DisableIfArgumentExtension.java
index cea44e44f..579fde35b 100644
--- a/src/main/java/org/junitpioneer/jupiter/params/DisableIfArgumentExtension.java
+++ b/src/main/java/org/junitpioneer/jupiter/params/DisableIfArgumentExtension.java
@@ -15,7 +15,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
@@ -70,33 +69,30 @@ public void interceptTestTemplateMethod(Invocation invocation,
}
private static void checkRequiredAnnotations(Method testMethod) {
- if (!AnnotationSupport.findAnnotation(testMethod, DisableIfAnyArgument.class).isPresent()
- && !AnnotationSupport.findAnnotation(testMethod, DisableIfAllArguments.class).isPresent()
+ if (AnnotationSupport.findAnnotation(testMethod, DisableIfAnyArgument.class).isEmpty()
+ && AnnotationSupport.findAnnotation(testMethod, DisableIfAllArguments.class).isEmpty()
&& AnnotationSupport.findRepeatableAnnotations(testMethod, DisableIfArgument.class).isEmpty()) {
throw new ExtensionConfigurationException(
"Required at least one of the following: @DisableIfArgument, @DisableIfAllArguments, @DisableIfAnyArgument but found none.");
}
}
- private static DisableIfAllArguments verifyNonEmptyInputs(DisableIfAllArguments annotation) {
+ private static void verifyNonEmptyInputs(DisableIfAllArguments annotation) {
if (annotation.contains().length > 0 == annotation.matches().length > 0)
throw invalidInputs(DisableIfAllArguments.class);
- return annotation;
}
- private static DisableIfAnyArgument verifyNonEmptyInputs(DisableIfAnyArgument annotation) {
+ private static void verifyNonEmptyInputs(DisableIfAnyArgument annotation) {
if (annotation.contains().length > 0 == annotation.matches().length > 0)
throw invalidInputs(DisableIfAnyArgument.class);
- return annotation;
}
- private static DisableIfArgument verifyNonEmptyInputs(DisableIfArgument annotation) {
+ private static void verifyNonEmptyInputs(DisableIfArgument annotation) {
if (annotation.contains().length > 0 == annotation.matches().length > 0)
throw invalidInputs(DisableIfArgument.class);
- return annotation;
}
- private static RuntimeException invalidInputs(Class> annotationClass) {
+ private static ExtensionConfigurationException invalidInputs(Class> annotationClass) {
return new ExtensionConfigurationException(
format("%s requires that either `contains` or `matches` is set.", annotationClass.getSimpleName()));
}
@@ -164,7 +160,7 @@ static ArgumentChecker checkAny(List arguments) {
}
static ArgumentChecker check(Object argument) {
- return new ArgumentChecker(Collections.singletonList(argument), true);
+ return new ArgumentChecker(List.of(argument), true);
}
public void matches(String[] matches) {
diff --git a/src/main/java/org/junitpioneer/jupiter/params/DisableIfNameExtension.java b/src/main/java/org/junitpioneer/jupiter/params/DisableIfNameExtension.java
index 9b22d3ca6..3c2f32378 100644
--- a/src/main/java/org/junitpioneer/jupiter/params/DisableIfNameExtension.java
+++ b/src/main/java/org/junitpioneer/jupiter/params/DisableIfNameExtension.java
@@ -11,10 +11,10 @@
package org.junitpioneer.jupiter.params;
import static java.lang.String.format;
+import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled;
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
@@ -64,7 +64,7 @@ private ConditionEvaluationResult disableIfContains(String displayName, String[]
String matches = Stream
.of(substrings)
.filter(displayName::contains)
- .collect(Collectors.joining("', '"));
+ .collect(joining("', '"));
return matches.isEmpty()
? enabled(reason(displayName, "doesn't contain any substring."))
: disabled(reason(displayName, format("contains '%s'.", matches)));
@@ -76,7 +76,7 @@ private ConditionEvaluationResult disableIfMatches(String displayName, String[]
String matches = Stream
.of(regExps)
.filter(displayName::matches)
- .collect(Collectors.joining("', '"));
+ .collect(joining("', '"));
return matches.isEmpty()
? enabled(reason(displayName, "doesn't match any regular expression."))
: disabled(reason(displayName, format("matches '%s'.",matches)));
diff --git a/src/main/java/org/junitpioneer/jupiter/params/Range.java b/src/main/java/org/junitpioneer/jupiter/params/Range.java
index ca916288b..01cb66c51 100644
--- a/src/main/java/org/junitpioneer/jupiter/params/Range.java
+++ b/src/main/java/org/junitpioneer/jupiter/params/Range.java
@@ -19,13 +19,13 @@
*/
abstract class Range> implements Iterator {
- private N from;
- private N to;
- private N step;
- private boolean closed;
+ private final N from;
+ private final N to;
+ private final N step;
+ private final boolean closed;
private N current;
- private int sign;
- private N zero;
+ private final int sign;
+ private final N zero;
Range(N from, N to, N step, boolean closed, N zero) {
this.from = from;
diff --git a/src/main/java/org/junitpioneer/jupiter/params/RangeClass.java b/src/main/java/org/junitpioneer/jupiter/params/RangeClass.java
index 1badcc719..4c85a32a5 100644
--- a/src/main/java/org/junitpioneer/jupiter/params/RangeClass.java
+++ b/src/main/java/org/junitpioneer/jupiter/params/RangeClass.java
@@ -24,7 +24,6 @@
@Retention(RetentionPolicy.RUNTIME)
@interface RangeClass {
- @SuppressWarnings("rawtypes")
- Class extends Range> value();
+ Class extends Range>> value();
}
diff --git a/src/main/java/org/junitpioneer/jupiter/params/package-info.java b/src/main/java/org/junitpioneer/jupiter/params/package-info.java
index eebe7cd4f..e9322035e 100644
--- a/src/main/java/org/junitpioneer/jupiter/params/package-info.java
+++ b/src/main/java/org/junitpioneer/jupiter/params/package-info.java
@@ -1,8 +1,8 @@
/**
* Several extensions for working with {@code ParameterizedTest}s.
- *
- * Disable {@code @ParameterizedTest} executions based on conditions.
- * Check out the following types for details:
+ *
+ * Disable {@code @ParameterizedTest} executions based on conditions.
+ * Check out the following types for details:
*
* {@link org.junitpioneer.jupiter.params.DisableIfDisplayName}
* {@link org.junitpioneer.jupiter.params.DisableIfAllArguments}
@@ -10,8 +10,9 @@
* {@link org.junitpioneer.jupiter.params.DisableIfArgument}
*
*
- * Argument providers for a range of numbers.
- * Check out the following types for details on providing values for parameterized tests:
+ *
+ * Argument providers for a range of numbers.
+ * Check out the following types for details on providing values for parameterized tests:
*
* {@link org.junitpioneer.jupiter.params.ByteRangeSource}
* {@link org.junitpioneer.jupiter.params.ShortRangeSource}
@@ -20,6 +21,7 @@
* {@link org.junitpioneer.jupiter.params.FloatRangeSource}
* {@link org.junitpioneer.jupiter.params.DoubleRangeSource}
*
+ *
*/
package org.junitpioneer.jupiter.params;
diff --git a/src/main/java/org/junitpioneer/jupiter/resource/ResourceExtension.java b/src/main/java/org/junitpioneer/jupiter/resource/ResourceExtension.java
index 6f4258c21..08d5e4866 100644
--- a/src/main/java/org/junitpioneer/jupiter/resource/ResourceExtension.java
+++ b/src/main/java/org/junitpioneer/jupiter/resource/ResourceExtension.java
@@ -10,10 +10,8 @@
package org.junitpioneer.jupiter.resource;
-import static java.util.Arrays.asList;
-import static java.util.Collections.unmodifiableList;
import static java.util.Comparator.comparing;
-import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toUnmodifiableList;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
@@ -21,7 +19,6 @@
import java.lang.reflect.Parameter;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
@@ -182,9 +179,9 @@ private Object resolveShared(Shared sharedAnnotation, Parameter[] parameters, Ex
private Resource> newResource(Object newOrSharedAnnotation, ResourceFactory> resourceFactory) {
List arguments;
if (newOrSharedAnnotation instanceof New) {
- arguments = unmodifiableList(asList(((New) newOrSharedAnnotation).arguments()));
+ arguments = List.of(((New) newOrSharedAnnotation).arguments());
} else {
- arguments = Collections.emptyList();
+ arguments = List.of();
}
Resource> result;
@@ -386,7 +383,7 @@ private T runSequentially(Invocation invocation, Executable executable, E
// - test3 -> [C, A]
//
// If test1 gets A, then test2 gets B, and then test3 gets C, none of the tests can get the second lock
- // they need and so they can also never give up the one they hold.
+ // they need, and so they can also never give up the one they hold.
//
// This is known as the Dining Philosophers Problem [1] and a solution is to order locks before acquiring them.
// In the above example, test3 would start with trying to get A and, since it can't, block on that. Then test2
@@ -404,16 +401,19 @@ private T runSequentially(Invocation invocation, Executable executable, E
private List sortedLocksForSharedResources(Collection sharedAnnotations,
ExtensionContext extensionContext) {
- List sortedAnnotations = sharedAnnotations.stream().sorted(comparing(Shared::name)).collect(toList());
+ List sortedAnnotations = sharedAnnotations
+ .stream()
+ .sorted(comparing(Shared::name))
+ .collect(toUnmodifiableList());
List stores = //
sortedAnnotations
.stream() //
.map(shared -> scopedStore(extensionContext, shared.scope()))
- .collect(toList());
+ .collect(toUnmodifiableList());
return IntStream
.range(0, sortedAnnotations.size()) //
.mapToObj(i -> findLockForShared(sortedAnnotations.get(i), stores.get(i)))
- .collect(toList());
+ .collect(toUnmodifiableList());
}
private Method testFactoryMethod(ExtensionContext extensionContext) {
@@ -455,7 +455,7 @@ private List findShared(Executable executable) {
.map(parameter -> AnnotationSupport.findAnnotation(parameter, Shared.class))
.filter(Optional::isPresent)
.map(Optional::get)
- .collect(toList());
+ .collect(toUnmodifiableList());
}
private void putNewLockForShared(Shared shared, ExtensionContext.Store store) {
diff --git a/src/main/java/org/junitpioneer/vintage/TimeoutExtension.java b/src/main/java/org/junitpioneer/vintage/TimeoutExtension.java
index 5d04f6827..f77349739 100644
--- a/src/main/java/org/junitpioneer/vintage/TimeoutExtension.java
+++ b/src/main/java/org/junitpioneer/vintage/TimeoutExtension.java
@@ -29,7 +29,7 @@
*
* Note that this is different from JUnit 4's {@code @Test} parameter, which would abandon the test if it ran to
* long and continue with the remainder of the suite. As Jupiter's extension API is currently not powerful enough
- * to interact with its threading model, this could not be implemented.
+ * to interact with its threading model, this could not be implemented.
*/
class TimeoutExtension implements InvocationInterceptor {
diff --git a/src/test/java/org/junitpioneer/internal/PioneerPreconditionsTests.java b/src/test/java/org/junitpioneer/internal/PioneerPreconditionsTests.java
index cbc1a6c71..ddeffc656 100644
--- a/src/test/java/org/junitpioneer/internal/PioneerPreconditionsTests.java
+++ b/src/test/java/org/junitpioneer/internal/PioneerPreconditionsTests.java
@@ -13,9 +13,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
+import java.util.Set;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
@@ -96,7 +95,7 @@ void nullCollectionInput() {
@Test
@DisplayName("should throw violation exception if collection is empty")
void emptyInput() {
- assertThatThrownBy(() -> PioneerPreconditions.notEmpty(Collections.emptySet(), "Value must be provided"))
+ assertThatThrownBy(() -> PioneerPreconditions.notEmpty(Set.of(), "Value must be provided"))
.isInstanceOf(PreconditionViolationException.class)
.hasMessage("Value must be provided");
}
@@ -104,8 +103,7 @@ void emptyInput() {
@Test
@DisplayName("should return collection if it is not empty")
void validInput() {
- List collection = new ArrayList<>();
- collection.add("testValue");
+ List collection = List.of("testValue");
assertThat(PioneerPreconditions.notEmpty(collection, "Value must be provided")).isSameAs(collection);
}
@@ -126,8 +124,7 @@ void nullCollectionInput() {
@Test
@DisplayName("should throw violation exception if collection is empty")
void emptyInput() {
- assertThatThrownBy(
- () -> PioneerPreconditions.notEmpty(Collections.emptySet(), "Collection must be provided"))
+ assertThatThrownBy(() -> PioneerPreconditions.notEmpty(Set.of(), "Collection must be provided"))
.isInstanceOf(PreconditionViolationException.class)
.hasMessage("Collection must be provided");
}
@@ -135,8 +132,7 @@ void emptyInput() {
@Test
@DisplayName("should return collection if it is not empty")
void validInput() {
- List collection = new ArrayList<>();
- collection.add("testValue");
+ List collection = List.of("testValue");
assertThat(PioneerPreconditions.notEmpty(collection, "Collection must be provided")).isSameAs(collection);
}
diff --git a/src/test/java/org/junitpioneer/jupiter/EnvironmentVariableUtilsTests.java b/src/test/java/org/junitpioneer/jupiter/EnvironmentVariableUtilsTests.java
index f952954e6..c6722e60e 100644
--- a/src/test/java/org/junitpioneer/jupiter/EnvironmentVariableUtilsTests.java
+++ b/src/test/java/org/junitpioneer/jupiter/EnvironmentVariableUtilsTests.java
@@ -14,7 +14,6 @@
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
@@ -44,7 +43,7 @@ void theEnvironmentIsNotCorruptedAfterSet() {
/* By using this method, the entire environment is read and copied from the field
ProcessEnvironment.theEnvironment. If that field is corrupted by a String having been stored
as key or value, this copy operation will fail with a ClassCastException. */
- Map environmentCopy = new HashMap<>(System.getenv());
+ Map environmentCopy = Map.copyOf(System.getenv());
assertThat(environmentCopy.get("TEST")).isEqualTo("test");
}
diff --git a/src/test/java/org/junitpioneer/jupiter/json/JsonClasspathSourceArgumentsProviderTests.java b/src/test/java/org/junitpioneer/jupiter/json/JsonClasspathSourceArgumentsProviderTests.java
index 898090f0b..6434bfa1c 100644
--- a/src/test/java/org/junitpioneer/jupiter/json/JsonClasspathSourceArgumentsProviderTests.java
+++ b/src/test/java/org/junitpioneer/jupiter/json/JsonClasspathSourceArgumentsProviderTests.java
@@ -10,14 +10,16 @@
package org.junitpioneer.jupiter.json;
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.mapping;
+import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.junitpioneer.testkit.assertion.PioneerAssert.assertThat;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
+import java.util.Set;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
@@ -47,9 +49,8 @@ void assertAllValuesSupplied() {
Map> displayNames = results
.dynamicallyRegisteredEvents()
.map(Event::getTestDescriptor)
- .collect(Collectors
- .groupingBy(JsonClasspathSourceArgumentsProviderTests::testSourceMethodName,
- Collectors.mapping(TestDescriptor::getDisplayName, Collectors.toList())));
+ .collect(groupingBy(JsonClasspathSourceArgumentsProviderTests::testSourceMethodName,
+ mapping(TestDescriptor::getDisplayName, toList())));
assertThat(displayNames)
.containsOnlyKeys("singleObject", "singleObjectAttribute", "deconstructObjectsFromArray",
@@ -80,9 +81,8 @@ void assertAllCartesianValuesSupplied() {
Map> displayNames = results
.dynamicallyRegisteredEvents()
.map(Event::getTestDescriptor)
- .collect(Collectors
- .groupingBy(JsonClasspathSourceArgumentsProviderTests::testSourceMethodName,
- Collectors.mapping(TestDescriptor::getDisplayName, Collectors.toList())));
+ .collect(groupingBy(JsonClasspathSourceArgumentsProviderTests::testSourceMethodName,
+ mapping(TestDescriptor::getDisplayName, toList())));
assertThat(displayNames)
.containsOnlyKeys("singleObject", "singleObjectProperty", "deconstructObjectsFromArray",
@@ -123,7 +123,7 @@ class JsonClasspathSourceTests {
@ParameterizedTest
@JsonClasspathSource(JEDIS)
void singleObject(Jedi jedi) {
- assertThat(Collections.singleton(tuple(jedi.getName(), jedi.getHeight())))
+ assertThat(Set.of(tuple(jedi.getName(), jedi.getHeight())))
.containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@@ -136,27 +136,27 @@ void singleObjectAttribute(@Property("name") String name) {
@ParameterizedTest
@JsonClasspathSource(JEDIS)
void deconstructObjectsFromArray(@Property("name") String name, @Property("height") int height) {
- assertThat(Collections.singleton(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
+ assertThat(Set.of(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@ParameterizedTest
@JsonClasspathSource(value = LUKE, data = "vehicles")
void customDataLocation(@Property("name") String name, @Property("length") double length) {
- assertThat(Collections.singleton(tuple(name, length)))
+ assertThat(Set.of(tuple(name, length)))
.containsAnyOf(tuple("Snowspeeder", 4.5), tuple("Imperial Speeder Bike", 3d));
}
@ParameterizedTest
@JsonClasspathSource({ YODA, LUKE, })
void deconstructObjectsFromMultipleFiles(@Property("height") int height, @Property("name") String name) {
- assertThat(Collections.singleton(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
+ assertThat(Set.of(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@ParameterizedTest
@JsonClasspathSource({ YODA, LUKE })
void deconstructObjectsFromMultipleFilesIntoComplexType(@Property("name") String name,
@Property("location") Location location) {
- assertThat(Collections.singleton(tuple(name, location.getName())))
+ assertThat(Set.of(tuple(name, location.getName())))
.containsAnyOf(tuple("Luke", "Tatooine"), tuple("Yoda", "unknown"));
}
@@ -167,7 +167,7 @@ class JsonClasspathSourceCartesianTests {
@CartesianTest
void singleObject(@JsonClasspathSource(JEDIS) Jedi jedi) {
- assertThat(Collections.singleton(tuple(jedi.getName(), jedi.getHeight())))
+ assertThat(Set.of(tuple(jedi.getName(), jedi.getHeight())))
.containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
diff --git a/src/test/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProviderTests.java b/src/test/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProviderTests.java
index 4877e36ea..1e7284865 100644
--- a/src/test/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProviderTests.java
+++ b/src/test/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProviderTests.java
@@ -10,14 +10,16 @@
package org.junitpioneer.jupiter.json;
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.mapping;
+import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.junitpioneer.testkit.assertion.PioneerAssert.assertThat;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
+import java.util.Set;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
@@ -48,9 +50,8 @@ void assertAllValuesSupplied() {
Map> displayNames = results
.dynamicallyRegisteredEvents()
.map(Event::getTestDescriptor)
- .collect(Collectors
- .groupingBy(JsonFileSourceArgumentsProviderTests::testSourceMethodName,
- Collectors.mapping(TestDescriptor::getDisplayName, Collectors.toList())));
+ .collect(groupingBy(JsonFileSourceArgumentsProviderTests::testSourceMethodName,
+ mapping(TestDescriptor::getDisplayName, toList())));
assertThat(displayNames)
.containsOnlyKeys("singleObject", "singleObjectAttribute", "deconstructObjectsFromArray",
@@ -81,9 +82,8 @@ void assertAllCartesianValuesSupplied() {
Map> displayNames = results
.dynamicallyRegisteredEvents()
.map(Event::getTestDescriptor)
- .collect(Collectors
- .groupingBy(JsonFileSourceArgumentsProviderTests::testSourceMethodName,
- Collectors.mapping(TestDescriptor::getDisplayName, Collectors.toList())));
+ .collect(groupingBy(JsonFileSourceArgumentsProviderTests::testSourceMethodName,
+ mapping(TestDescriptor::getDisplayName, toList())));
assertThat(displayNames)
.containsOnlyKeys("singleObject", "singleObjectProperty", "deconstructObjectsFromArray",
@@ -124,7 +124,7 @@ class JsonFileSourceTests {
@ParameterizedTest
@JsonFileSource(JEDIS)
void singleObject(Jedi jedi) {
- assertThat(Collections.singleton(tuple(jedi.getName(), jedi.getHeight())))
+ assertThat(Set.of(tuple(jedi.getName(), jedi.getHeight())))
.containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@@ -137,27 +137,27 @@ void singleObjectAttribute(@Property("name") String name) {
@ParameterizedTest
@JsonFileSource(JEDIS)
void deconstructObjectsFromArray(@Property("name") String name, @Property("height") int height) {
- assertThat(Collections.singleton(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
+ assertThat(Set.of(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@ParameterizedTest
@JsonFileSource(value = LUKE, data = "vehicles")
void customDataLocation(@Property("name") String name, @Property("length") double length) {
- assertThat(Collections.singleton(tuple(name, length)))
+ assertThat(Set.of(tuple(name, length)))
.containsAnyOf(tuple("Snowspeeder", 4.5), tuple("Imperial Speeder Bike", 3d));
}
@ParameterizedTest
@JsonFileSource({ YODA, LUKE, })
void deconstructObjectsFromMultipleFiles(@Property("height") int height, @Property("name") String name) {
- assertThat(Collections.singleton(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
+ assertThat(Set.of(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@ParameterizedTest
@JsonFileSource({ YODA, LUKE })
void deconstructObjectsFromMultipleFilesIntoComplexType(@Property("name") String name,
@Property("location") Location location) {
- assertThat(Collections.singleton(tuple(name, location.getName())))
+ assertThat(Set.of(tuple(name, location.getName())))
.containsAnyOf(tuple("Luke", "Tatooine"), tuple("Yoda", "unknown"));
}
@@ -168,7 +168,7 @@ class JsonFileSourceCartesianTests {
@CartesianTest
void singleObject(@JsonFileSource(JEDIS) Jedi jedi) {
- assertThat(Collections.singleton(tuple(jedi.getName(), jedi.getHeight())))
+ assertThat(Set.of(tuple(jedi.getName(), jedi.getHeight())))
.containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
diff --git a/src/test/java/org/junitpioneer/jupiter/json/JsonSourceArgumentsProviderTests.java b/src/test/java/org/junitpioneer/jupiter/json/JsonSourceArgumentsProviderTests.java
index 2e1e750fb..9d9f7231d 100644
--- a/src/test/java/org/junitpioneer/jupiter/json/JsonSourceArgumentsProviderTests.java
+++ b/src/test/java/org/junitpioneer/jupiter/json/JsonSourceArgumentsProviderTests.java
@@ -10,14 +10,16 @@
package org.junitpioneer.jupiter.json;
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.mapping;
+import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.junitpioneer.testkit.assertion.PioneerAssert.assertThat;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
+import java.util.Set;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
@@ -44,9 +46,8 @@ void assertAllValuesSupplied() {
Map> displayNames = results
.dynamicallyRegisteredEvents()
.map(Event::getTestDescriptor)
- .collect(Collectors
- .groupingBy(JsonSourceArgumentsProviderTests::testSourceMethodName,
- Collectors.mapping(TestDescriptor::getDisplayName, Collectors.toList())));
+ .collect(groupingBy(JsonSourceArgumentsProviderTests::testSourceMethodName,
+ mapping(TestDescriptor::getDisplayName, toList())));
assertThat(displayNames)
.containsOnlyKeys("deconstructCustomerFromArray", "deconstructCustomerMultipleValues",
@@ -72,9 +73,8 @@ void assertAllCartesianValuesSupplied() {
Map> displayNames = results
.dynamicallyRegisteredEvents()
.map(Event::getTestDescriptor)
- .collect(Collectors
- .groupingBy(JsonSourceArgumentsProviderTests::testSourceMethodName,
- Collectors.mapping(TestDescriptor::getDisplayName, Collectors.toList())));
+ .collect(groupingBy(JsonSourceArgumentsProviderTests::testSourceMethodName,
+ mapping(TestDescriptor::getDisplayName, toList())));
assertThat(displayNames)
.containsOnlyKeys("extractPropertyFromArray", "extractPropertyFromMultipleValues",
@@ -113,13 +113,13 @@ class JsonSourceTests {
@ParameterizedTest
@JsonSource("[ { name: 'Luke', height: 172 }, { name: 'Yoda', height: 66 } ]")
void deconstructCustomerFromArray(@Property("name") String name, @Property("height") int height) {
- assertThat(Collections.singleton(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
+ assertThat(Set.of(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@ParameterizedTest
@JsonSource({ "{ name: 'Yoda', height: 66 }", "{ name: 'Luke', height: 172 }", })
void deconstructCustomerMultipleValues(@Property("height") int height, @Property("name") String name) {
- assertThat(Collections.singleton(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
+ assertThat(Set.of(tuple(name, height))).containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@ParameterizedTest
@@ -128,14 +128,14 @@ void deconstructCustomerMultipleValues(@Property("height") int height, @Property
void deconstructCustomerMultipleLinesComplexType(@Property("name") String name,
@Property("location") Location location) {
- assertThat(Collections.singleton(tuple(name, location.getName())))
+ assertThat(Set.of(tuple(name, location.getName())))
.containsAnyOf(tuple("Luke", "Tatooine"), tuple("Yoda", "unknown"));
}
@ParameterizedTest
@JsonSource("[ { name: 'Luke', height: 172 }, { name: 'Yoda', height: 66 } ]")
void singleCustomer(Customer customer) {
- assertThat(Collections.singleton(tuple(customer.getName(), customer.getHeight())))
+ assertThat(Set.of(tuple(customer.getName(), customer.getHeight())))
.containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
@@ -155,7 +155,7 @@ class JsonSourceCartesianTests {
void extractPropertyFromArray(
@JsonSource("[ { name: 'Luke', height: 172 }, { name: 'Yoda', height: 66 } ]") @Property("name") String name,
@JsonSource("[ { name: 'Luke', height: 172 }, { name: 'Yoda', height: 66 } ]") @Property("height") int height) {
- assertThat(Collections.singleton(tuple(name, height)))
+ assertThat(Set.of(tuple(name, height)))
.containsAnyOf(tuple("Luke", 172), tuple("Luke", 66), tuple("Yoda", 172), tuple("Yoda", 66));
}
@@ -166,7 +166,7 @@ void extractPropertyFromMultipleValues(
"{ name: 'Luke', height: 172 }", }) @Property("height") int height,
@JsonSource({ "{ name: 'Yoda', height: 66 }",
"{ name: 'Luke', height: 172 }", }) @Property("name") String name) {
- assertThat(Collections.singleton(tuple(name, height)))
+ assertThat(Set.of(tuple(name, height)))
.containsAnyOf(tuple("Luke", 172), tuple("Luke", 66), tuple("Yoda", 172), tuple("Yoda", 66));
}
@@ -178,7 +178,7 @@ void extractPropertyMultipleLinesWithComplexType(@JsonSource({
@JsonSource({ "{ name: 'Yoda', height: 66, location: { name: 'unknown' } }",
"{ name: 'Luke', height: 172, location: { name: 'Tatooine' } }", }) @Property("location") Location location) {
- assertThat(Collections.singleton(tuple(name, location.getName())))
+ assertThat(Set.of(tuple(name, location.getName())))
.containsAnyOf(tuple("Luke", "Tatooine"), tuple("Luke", "unknown"), tuple("Yoda", "Tatooine"),
tuple("Yoda", "unknown"));
}
diff --git a/src/test/java/org/junitpioneer/jupiter/params/RangeSourceArgumentsProviderTests.java b/src/test/java/org/junitpioneer/jupiter/params/RangeSourceArgumentsProviderTests.java
index 867b4d8e0..a10339cbd 100644
--- a/src/test/java/org/junitpioneer/jupiter/params/RangeSourceArgumentsProviderTests.java
+++ b/src/test/java/org/junitpioneer/jupiter/params/RangeSourceArgumentsProviderTests.java
@@ -10,13 +10,13 @@
package org.junitpioneer.jupiter.params;
+import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junitpioneer.testkit.assertion.PioneerAssert.assertThat;
import java.lang.reflect.Method;
import java.util.List;
import java.util.function.Function;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
@@ -62,7 +62,7 @@ void assertAllValuesSupplied() {
.dynamicallyRegisteredEvents()
.map(e -> e.getTestDescriptor().getDisplayName())
.map(RangeSourceArgumentsProviderTests::displayNameToNumber)
- .collect(Collectors.toList());
+ .collect(toList());
assertThat(actualValues).containsExactlyInAnyOrder(expectedValues);
}
diff --git a/src/test/java/org/junitpioneer/testkit/assertion/PioneerExecutionResultAssert.java b/src/test/java/org/junitpioneer/testkit/assertion/PioneerExecutionResultAssert.java
index a2b75fa0f..810b8ce63 100644
--- a/src/test/java/org/junitpioneer/testkit/assertion/PioneerExecutionResultAssert.java
+++ b/src/test/java/org/junitpioneer/testkit/assertion/PioneerExecutionResultAssert.java
@@ -17,7 +17,6 @@
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Predicate;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@@ -56,7 +55,7 @@ public ReportEntryContentAssert hasNumberOfReportEntries(int expected) {
List> entryList = entries
.stream()
.flatMap(map -> map.entrySet().stream())
- .collect(Collectors.toList());
+ .collect(toList());
return new ReportEntryAssertBase(entryList, expected);
}
diff --git a/src/test/java/org/junitpioneer/testkit/assertion/PioneerPathAssert.java b/src/test/java/org/junitpioneer/testkit/assertion/PioneerPathAssert.java
index 3f2674378..033d4f2d6 100644
--- a/src/test/java/org/junitpioneer/testkit/assertion/PioneerPathAssert.java
+++ b/src/test/java/org/junitpioneer/testkit/assertion/PioneerPathAssert.java
@@ -11,11 +11,11 @@
package org.junitpioneer.testkit.assertion;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.util.Collections.singletonList;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.List;
import java.util.Objects;
import org.assertj.core.api.PathAssert;
@@ -39,7 +39,7 @@ public PioneerPathAssert canReadAndWriteFile() {
String expectedText = "some-text";
try {
- Files.write(textFile, singletonList(expectedText));
+ Files.write(textFile, List.of(expectedText));
}
catch (IOException e) {
throw failure("Cannot write to a file");
diff --git a/src/test/java/org/junitpioneer/testkit/assertion/ReportEntryAssertBase.java b/src/test/java/org/junitpioneer/testkit/assertion/ReportEntryAssertBase.java
index d3592402b..96e6f0965 100644
--- a/src/test/java/org/junitpioneer/testkit/assertion/ReportEntryAssertBase.java
+++ b/src/test/java/org/junitpioneer/testkit/assertion/ReportEntryAssertBase.java
@@ -10,16 +10,15 @@
package org.junitpioneer.testkit.assertion;
+import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.assertj.core.api.AbstractStringAssert;
@@ -56,10 +55,10 @@ public void withKeyValuePairs(String... keyAndValuePairs) {
assertThat(actual).containsExactlyInAnyOrderElementsOf(asEntryList(keyAndValuePairs));
}
- private Iterable> asEntryList(String... values) {
- List> entryList = new ArrayList<>();
+ private Iterable> asEntryList(String... values) {
+ List> entryList = new ArrayList<>();
for (int i = 0; i < values.length; i += 2) {
- entryList.add(new AbstractMap.SimpleEntry<>(values[i], values[i + 1]));
+ entryList.add(Map.entry(values[i], values[i + 1]));
}
return entryList;
}
@@ -75,11 +74,11 @@ public void andThen(BiConsumer testFunction) {
}
private List getValues() {
- return this.actual.stream().map(Map.Entry::getValue).collect(Collectors.toList());
+ return this.actual.stream().map(Map.Entry::getValue).collect(toList());
}
private List getKeys() {
- return this.actual.stream().map(Map.Entry::getKey).collect(Collectors.toList());
+ return this.actual.stream().map(Map.Entry::getKey).collect(toList());
}
@Override