Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import junitbuild.extensions.dependencyFromLibs
import net.ltgt.gradle.errorprone.errorprone
import net.ltgt.gradle.nullaway.nullaway
import org.gradle.jvm.toolchain.JvmImplementation.J9
import java.lang.System.getenv

plugins {
`java-library`
Expand All @@ -16,51 +18,56 @@ dependencies {

tasks.withType<JavaCompile>().configureEach {
options.errorprone {
val shouldDisableErrorProne = java.toolchain.implementation.orNull == JvmImplementation.J9
if (name == "compileJava" && !shouldDisableErrorProne) {
disable(
"AnnotateFormatMethod", // We don`t want to use ErrorProne's annotations.
"BadImport", // This check is opinionated wrt. which method names it considers unsuitable for import which includes a few of our own methods in `ReflectionUtils` etc.
"DoNotCallSuggester", // We don`t want to use ErrorProne's annotations.
"ImmutableEnumChecker", // We don`t want to use ErrorProne's annotations.
"InlineMeSuggester", // We don`t want to use ErrorProne's annotations.
"MissingSummary", // Produces a lot of findings that we consider to be false positives, for example for package-private classes and methods.
"StringSplitter", // We don`t want to use Guava.
"UnnecessaryLambda", // The findings of this check are subjective because a named constant can be more readable in many cases.
val enableErrorProne = java.toolchain.implementation.orNull != J9
if (enableErrorProne && name == "compileJava") {
disableAllWarnings = true // considering this immense spam burden, remove this once to fix dedicated flaw. https://github.com/diffplug/spotless/pull/2766
disable( // We don`t want to use ErrorProne's annotations.
// picnic (https://error-prone.picnic.tech)
"ConstantNaming",
"DirectReturn", // We don`t want to use this: https://github.com/junit-team/junit-framework/pull/5006#discussion_r2403984446
"DirectReturn", // We don`t want to use this. https://github.com/junit-team/junit-framework/pull/5006#discussion_r2403984446
"FormatStringConcatenation",
"IdentityConversion",
"LexicographicalAnnotationAttributeListing", // We don`t want to use this: https://github.com/junit-team/junit-framework/pull/5043#pullrequestreview-3330615838
"LexicographicalAnnotationAttributeListing", // We don`t want to use this. https://github.com/junit-team/junit-framework/pull/5043#pullrequestreview-3330615838
"LexicographicalAnnotationListing",
"MissingTestCall",
"NestedOptionals",
"NonStaticImport",
"OptionalOrElseGet",
"PrimitiveComparison",
"StaticImport",
"TimeZoneUsage",
)
error(
"CanonicalAnnotationSyntax",
"IsInstanceLambdaUsage",
"MissingOverride",
"NonStaticImport",
"PackageLocation",
"RedundantStringConversion",
"RedundantStringEscape",
"SelfAssignment",
"StaticImport",
"StringCharset",
"StringJoin",
)
if (!getenv().containsKey("CI") && getenv("IN_PLACE").toBoolean()) {
errorproneArgs.addAll(
"-XepPatchLocation:IN_PLACE",
"-XepPatchChecks:" +
"NonStaticImport," +
"StaticImport,"
)
}
} else {
disableAllChecks = true
}
nullaway {
if (shouldDisableErrorProne) {
disable()
} else {
if (enableErrorProne) {
enable()
} else {
disable()
}
onlyNullMarked = true
isJSpecifyMode = true
checkContracts = true
isJSpecifyMode = true
onlyNullMarked = true
suppressionNameAliases.add("DataFlowIssue")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

package org.junit.jupiter.api;

import static java.util.Collections.shuffle;
import static java.util.Comparator.comparing;
import static java.util.Comparator.comparingInt;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.apiguardian.api.API.Status.STABLE;

import java.util.Collections;
import java.util.Comparator;

import org.apiguardian.api.API;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void orderClasses(ClassOrdererContext context) {
context.getClassDescriptors().sort(comparator);
}

private static final Comparator<ClassDescriptor> comparator = Comparator.comparing(
private static final Comparator<ClassDescriptor> comparator = comparing(
descriptor -> descriptor.getTestClass().getName());
}

Expand All @@ -171,8 +172,7 @@ public void orderClasses(ClassOrdererContext context) {
context.getClassDescriptors().sort(comparator);
}

private static final Comparator<ClassDescriptor> comparator = Comparator.comparing(
ClassDescriptor::getDisplayName);
private static final Comparator<ClassDescriptor> comparator = comparing(ClassDescriptor::getDisplayName);
}

/**
Expand Down Expand Up @@ -265,7 +265,7 @@ public Random() {
*/
@Override
public void orderClasses(ClassOrdererContext context) {
Collections.shuffle(context.getClassDescriptors(),
shuffle(context.getClassDescriptors(),
new java.util.Random(RandomOrdererUtils.getSeed(context::getConfigurationParameter, logger)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

package org.junit.jupiter.api;

import static java.util.Collections.shuffle;
import static java.util.Comparator.comparing;
import static java.util.Comparator.comparingInt;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.apiguardian.api.API.Status.STABLE;

import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Comparator;
import java.util.Optional;

Expand Down Expand Up @@ -214,8 +215,7 @@ public void orderMethods(MethodOrdererContext context) {
context.getMethodDescriptors().sort(comparator);
}

private static final Comparator<MethodDescriptor> comparator = Comparator.comparing(
MethodDescriptor::getDisplayName);
private static final Comparator<MethodDescriptor> comparator = comparing(MethodDescriptor::getDisplayName);
}

/**
Expand Down Expand Up @@ -308,7 +308,7 @@ public Random() {
*/
@Override
public void orderMethods(MethodOrdererContext context) {
Collections.shuffle(context.getMethodDescriptors(),
shuffle(context.getMethodDescriptors(),
new java.util.Random(RandomOrdererUtils.getSeed(context::getConfigurationParameter, logger)));
}

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

package org.junit.jupiter.api.extension;

import static java.util.Collections.reverse;
import static org.apiguardian.api.API.Status.STABLE;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
Expand Down Expand Up @@ -114,7 +114,7 @@ static void preDestroyTestInstances(ExtensionContext context, Consumer<Object> c
current.get().getTestInstances().map(TestInstances::getAllInstances).ifPresent(
destroyedInstances::removeAll);
}
Collections.reverse(destroyedInstances);
reverse(destroyedInstances);
destroyedInstances.forEach(callback);
}

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

package org.junit.jupiter.engine.descriptor;

import static java.util.Collections.reverse;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static org.apiguardian.api.API.Status.INTERNAL;
Expand All @@ -30,7 +31,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -516,7 +516,7 @@ private void registerAfterEachMethodAdapters(ExtensionRegistrar registrar) {
// synthesized AfterEachMethodAdapters are executed within TestMethodTestDescriptor,
// we have to reverse the afterEachMethods list to put them in top-down order before
// we register them as synthesized extensions.
Collections.reverse(afterEachMethods);
reverse(afterEachMethods);

registerMethodsAsExtensions(afterEachMethods, registrar, this::synthesizeAfterEachMethodAdapter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.junit.jupiter.engine.descriptor;

import static java.util.Comparator.comparingInt;
import static java.util.stream.Collectors.toList;
import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;
import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
Expand Down Expand Up @@ -226,7 +227,7 @@ private static Stream<Class<? extends Extension>> streamDeclarativeExtensionType
* @since 5.4
*/
private static final Comparator<Field> orderComparator = //
Comparator.comparingInt(ExtensionUtils::getOrder);
comparingInt(ExtensionUtils::getOrder);

/**
* @since 5.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.junit.jupiter.engine.descriptor;

import static java.util.Collections.emptySet;
import static java.util.Collections.reverse;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
import static java.util.stream.Collectors.toSet;
Expand Down Expand Up @@ -108,7 +109,7 @@ <E extends Extension> void invokeExecutionExceptionHandlers(Class<E> handlerType
Throwable throwable, ExceptionHandlerInvoker<E> handlerInvoker) {

List<E> extensions = registry.getExtensions(handlerType);
Collections.reverse(extensions);
reverse(extensions);
invokeExecutionExceptionHandlers(extensions, throwable, handlerInvoker);
}

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

package org.junit.jupiter.engine.execution;

import static java.util.Collections.unmodifiableList;
import static org.apiguardian.api.API.Status.INTERNAL;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Optional;
Expand All @@ -32,7 +32,7 @@ public static DefaultTestInstances of(Object instance) {
public static DefaultTestInstances of(TestInstances testInstances, Object instance) {
List<Object> allInstances = new ArrayList<>(testInstances.getAllInstances());
allInstances.add(instance);
return new DefaultTestInstances(Collections.unmodifiableList(allInstances));
return new DefaultTestInstances(unmodifiableList(allInstances));
}

private final List<Object> instances;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import static java.nio.file.FileVisitResult.CONTINUE;
import static java.nio.file.FileVisitResult.SKIP_SUBTREE;
import static java.util.Collections.emptySortedMap;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope.TEST_METHOD;
import static org.junit.jupiter.api.io.CleanupMode.DEFAULT;
Expand Down Expand Up @@ -39,7 +40,6 @@
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.DosFileAttributeView;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedMap;
Expand Down Expand Up @@ -371,7 +371,7 @@ private SortedMap<Path, IOException> deleteAllFilesAndDirectories(FileOperations

Path rootDir = this.dir;
if (rootDir == null || Files.notExists(rootDir)) {
return Collections.emptySortedMap();
return emptySortedMap();
}

SortedMap<Path, IOException> failures = new TreeMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.junit.jupiter.migrationsupport.rules;

import static java.util.Collections.reverse;
import static java.util.Collections.unmodifiableList;
import static org.junit.platform.commons.support.AnnotationSupport.findPublicAnnotatedFields;
import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
Expand All @@ -19,7 +20,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
Expand Down Expand Up @@ -74,7 +74,7 @@ private List<TestRuleAnnotatedMember> findRuleAnnotatedMembers(Object testInstan
// Due to how rules are applied (see RunRules), the last rule gets called first.
// Rules from fields get called before those from methods.
// Thus, we first add methods and then fields and reverse the list in the end.
Collections.reverse(result);
reverse(result);
return unmodifiableList(result);
}

Expand Down Expand Up @@ -120,7 +120,7 @@ private int invokeAppropriateMethodOnRuleAnnotatedMembers(ExtensionContext conte

List<TestRuleAnnotatedMember> ruleAnnotatedMembers = getRuleAnnotatedMembers(context);
if (reverseOrder) {
Collections.reverse(ruleAnnotatedMembers);
reverse(ruleAnnotatedMembers);
}

AtomicInteger counter = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package org.junit.jupiter.params.converter;

import static java.util.Collections.unmodifiableMap;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand All @@ -23,7 +25,6 @@
import java.time.chrono.ChronoZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalQuery;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -48,7 +49,7 @@ class JavaTimeArgumentConverter extends AnnotationBasedArgumentConverter<JavaTim
queries.put(Year.class, Year::from);
queries.put(YearMonth.class, YearMonth::from);
queries.put(ZonedDateTime.class, ZonedDateTime::from);
TEMPORAL_QUERIES = Collections.unmodifiableMap(queries);
TEMPORAL_QUERIES = unmodifiableMap(queries);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

import static de.siegmar.fastcsv.reader.CommentStrategy.NONE;
import static de.siegmar.fastcsv.reader.CommentStrategy.SKIP;
import static java.util.UUID.randomUUID;

import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.nio.charset.Charset;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;

import de.siegmar.fastcsv.reader.CommentStrategy;
Expand Down Expand Up @@ -189,7 +189,7 @@ record DefaultFieldModifier(String emptyValue, Set<String> nullValues, boolean i
* <p>The marker is generated with a unique ID to ensure it cannot conflict
* with actual CSV content.
*/
static final String NULL_MARKER = "<null marker: %s>".formatted(UUID.randomUUID());
static final String NULL_MARKER = "<null marker: %s>".formatted(randomUUID());

@Override
public String modify(long unusedStartingLineNumber, int unusedFieldIdx, boolean quoted, String field) {
Expand Down
Loading