Skip to content
Merged
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
3 changes: 3 additions & 0 deletions documentation/src/main/java/example/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ public static boolean isPalindrome(@Nullable String candidate) {
return true;
}

private StringUtils() {
}

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

package org.junit.api.tools;

import static java.lang.String.format;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;

Expand Down Expand Up @@ -84,8 +83,8 @@ protected void printDeclarationSectionHeader(Set<Status> statuses, Status status
}
out.println(h2("@API(%s)".formatted(status)));
out.println();
out.println(
paragraph(format("Discovered %d " + code("@API(%s)") + " declarations.", declarations.size(), status)));
out.println(paragraph(
"Discovered %d %s declarations.".formatted(declarations.size(), code("@API(%s)".formatted(status)))));
out.println();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,7 @@ private static Stream<MethodInfo> collectMethods(ScanResult scanResult) {
.filter(m -> m.getAnnotationInfo(API.class) != null);
}

private ApiReportGenerator() {
}

}
11 changes: 11 additions & 0 deletions gradle/config/checkstyle/checkstyleMain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
<property name="message" value="Please use class literals for primitives and void -- for example, int.class instead of Integer.TYPE."/>
<property name="ignoreComments" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
<property name="id" value="stringFormattingMethod"/>
<property name="maximum" value="0"/>
<property name="format" value="String\.format"/>
<property name="message" value="Please use String.formatted() (non-static) rather than String.format() (static)."/>
<property name="ignoreComments" value="true"/>
</module>
<module name="HideUtilityClassConstructor"/>
<module name="ModifierOrder"/>
<module name="EqualsAvoidNull"/>
<module name="EmptyStatement"/>
</module>

<module name="JavadocPackage" />
Expand Down
7 changes: 7 additions & 0 deletions gradle/config/checkstyle/checkstyleTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
<property name="message" value="Please use class literals for primitives and void -- for example, int.class instead of Integer.TYPE."/>
<property name="ignoreComments" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
<property name="id" value="stringFormattingMethod"/>
<property name="maximum" value="0"/>
<property name="format" value="String\.format"/>
<property name="message" value="Please use String.formatted() (non-static) rather than String.format() (static)."/>
<property name="ignoreComments" value="true"/>
</module>
</module>

<module name="SuppressWarningsFilter" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,7 @@ public Thread newThread(Runnable r) {
}
}

private AssertTimeoutPreemptively() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ private static Optional<Long> getCustomSeed(Function<String, Optional<String>> c
return Long.valueOf(configurationParameter);
}
catch (NumberFormatException ex) {
logger.warn(ex,
() -> String.format(
"Failed to convert configuration parameter [%s] with value [%s] to a long. "
+ "Using default seed [%s] as fallback.",
RANDOM_SEED_PROPERTY_NAME, configurationParameter, DEFAULT_SEED));
logger.warn(ex, () -> """
Failed to convert configuration parameter [%s] with value [%s] to a long. \
Using default seed [%s] as fallback.""".formatted(RANDOM_SEED_PROPERTY_NAME,
configurationParameter, DEFAULT_SEED));
return null;
}
});
}

private RandomOrdererUtils() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ private Type getParameterType(ParameterContext parameterContext) {

private Type enclosedTypeOfParameterResolver() {
ParameterizedType typeBasedParameterResolverSuperclass = Preconditions.notNull(
findTypeBasedParameterResolverSuperclass(getClass()),
() -> String.format(
"Failed to discover parameter type supported by %s; "
+ "potentially caused by lacking parameterized type in class declaration.",
findTypeBasedParameterResolverSuperclass(getClass()), () -> """
Failed to discover parameter type supported by %s; \
potentially caused by lacking parameterized type in class declaration.""".formatted(
getClass().getName()));
return typeBasedParameterResolverSuperclass.getActualTypeArguments()[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public E get(String key, Function<String, Optional<String>> lookup, E defaultVal
catch (Exception ex) {
// local copy necessary for use in lambda expression
String constant = constantName;
logger.warn(() -> String.format(
"Invalid %s '%s' set via the '%s' configuration parameter. "
+ "Falling back to the %s default value.",
enumDisplayName, constant, key, defaultValue.name()));
logger.warn(() -> """
Invalid %s '%s' set via the '%s' configuration parameter. \
Falling back to the %s default value.""".formatted(enumDisplayName, constant, key,
defaultValue.name()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ private Supplier<Optional<T>> newInstanceSupplier(String className, String key)
}

private void logFailureMessage(String className, String key, Exception cause) {
logger.warn(cause,
() -> String.format("Failed to load default %s class '%s' set via the '%s' configuration parameter."
+ " Falling back to default behavior.",
this.name, className, key));
logger.warn(cause, () -> """
Failed to load default %s class '%s' set via the '%s' configuration parameter. \
Falling back to default behavior.""".formatted(this.name, className, key));
}

private void logSuccessMessage(String className, String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ protected interface CallbackInvoker<T extends Extension> {

}

private CallbackSupport() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ boolean mayReturnZeroContexts(ClassTemplateInvocationContextProvider provider,

@Override
protected String getZeroContextsProvidedErrorMessage(ClassTemplateInvocationContextProvider provider) {
return String.format(
"Provider [%s] did not provide any invocation contexts, but was expected to do so. "
+ "You may override mayReturnZeroClassTemplateInvocationContexts() to allow this.",
return """
Provider [%s] did not provide any invocation contexts, but was expected to do so. \
You may override mayReturnZeroClassTemplateInvocationContexts() to allow this.""".formatted(
provider.getClass().getSimpleName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@ private static Optional<DisplayNameGenerator> findDisplayNameGenerator(List<Clas
});
}

private DisplayNameUtils() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,11 @@ private static Extension readAndValidateExtensionFromField(Field field, @Nullabl

declarativeExtensionTypes.forEach(extensionType -> {
Class<?> valueType = value.getClass();
Preconditions.condition(!extensionType.equals(valueType),
() -> String.format(
"Failed to register extension via field [%s]. "
+ "The field registers an extension of type [%s] via @RegisterExtension and @ExtendWith, "
+ "but only one registration of a given extension type is permitted.",
field, valueType.getName()));
Preconditions.condition(!extensionType.equals(valueType), () -> """
Failed to register extension via field [%s]. \
The field registers an extension of type [%s] via @RegisterExtension and @ExtendWith, \
but only one registration of a given extension type is permitted.""".formatted(field,
valueType.getName()));
});

return (Extension) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ static MethodSource from(URI uri) {
String[] methodSpec = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName);
return MethodSource.from(methodSpec[0], methodSpec[1], methodSpec[2]);
}

private MethodSourceSupport() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ boolean mayReturnZeroContexts(TestTemplateInvocationContextProvider provider,

@Override
protected String getZeroContextsProvidedErrorMessage(TestTemplateInvocationContextProvider provider) {
return String.format(
"Provider [%s] did not provide any invocation contexts, but was expected to do so. "
+ "You may override mayReturnZeroTestTemplateInvocationContexts() to allow this.",
return """
Provider [%s] did not provide any invocation contexts, but was expected to do so. \
You may override mayReturnZeroTestTemplateInvocationContexts() to allow this.""".formatted(
provider.getClass().getSimpleName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ public static void resolveSelectors(EngineDiscoveryRequest request, JupiterEngin
resolver.resolve(request, engineDescriptor, issueReporter);
}

private DiscoverySelectorResolver() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ private Resolution resolve(Context context, List<Class<?>> enclosingClasses, Cla
// @formatter:on
if (matches.size() > 1) {
Stream<TestDescriptor> testDescriptors = matches.stream().map(Match::getTestDescriptor);
String message = String.format(
"Possible configuration error: method [%s] resulted in multiple TestDescriptors %s. "
+ "This is typically the result of annotating a method with multiple competing annotations "
+ "such as @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, etc.",
String message = """
Possible configuration error: method [%s] resulted in multiple TestDescriptors %s. \
This is typically the result of annotating a method with multiple competing annotations \
such as @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, etc.""".formatted(
method.toGenericString(), testDescriptors.map(d -> d.getClass().getName()).toList());
issueReporter.reportIssue(
DiscoveryIssue.builder(Severity.WARNING, message).source(MethodSource.from(method)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ private static boolean isCompatibleContainerType(Method method, DiscoveryIssueRe
}

private static DiscoveryIssue.Builder createTooGenericReturnTypeIssue(Method method) {
String message = String.format(
"The declared return type of @TestFactory method '%s' does not support static validation. It "
+ EXPECTED_RETURN_TYPE_MESSAGE + ".",
method.toGenericString());
String message = ("The declared return type of @TestFactory method '%s' does not support static validation. It "
+ EXPECTED_RETURN_TYPE_MESSAGE + ".").formatted(method.toGenericString());
return DiscoveryIssue.builder(Severity.INFO, message) //
.source(MethodSource.from(method));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ private static void validateResolvedType(Parameter parameter, @Nullable Object v
if (!isAssignableTo(value, type)) {
String message;
if (value == null && type.isPrimitive()) {
message = String.format(
"ParameterResolver [%s] resolved a null value for parameter [%s] "
+ "in %s [%s], but a primitive of type [%s] is required.",
message = """
ParameterResolver [%s] resolved a null value for parameter [%s] \
in %s [%s], but a primitive of type [%s] is required.""".formatted(
resolver.getClass().getName(), parameter, asLabel(executable), executable.toGenericString(),
type.getName());
}
else {
message = String.format(
"ParameterResolver [%s] resolved a value of type [%s] for parameter [%s] "
+ "in %s [%s], but a value assignment compatible with [%s] is required.",
message = """
ParameterResolver [%s] resolved a value of type [%s] for parameter [%s] \
in %s [%s], but a value assignment compatible with [%s] is required.""".formatted(
resolver.getClass().getName(), (value != null ? value.getClass().getName() : null), parameter,
asLabel(executable), executable.toGenericString(), type.getName());
}
Expand All @@ -210,4 +210,7 @@ private static String asLabel(Executable executable) {
return executable instanceof Constructor ? "constructor" : "method";
}

private ParameterResolutionUtils() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ private int failureThreshold(RepeatedTest repeatedTest, Method method) {
if (failureThreshold != Integer.MAX_VALUE) {
int repetitions = repeatedTest.value();
Preconditions.condition((failureThreshold > 0) && (failureThreshold < repetitions),
() -> String.format("Configuration error: @RepeatedTest on method [%s] must declare a "
+ "'failureThreshold' greater than zero and less than the total number of repetitions [%d].",
() -> """
Configuration error: @RepeatedTest on method [%s] must declare a \
'failureThreshold' greater than zero and less than the total number of repetitions [%d].""".formatted(
method, repetitions));
}
return failureThreshold;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ private boolean isLinkWithTargetOutsideTempDir(Path path) {

private void warnAboutLinkWithTargetOutsideTempDir(String linkType, Path file) throws IOException {
Path realPath = file.toRealPath();
LOGGER.warn(() -> String.format(
"Deleting %s from location inside of temp dir (%s) "
+ "to location outside of temp dir (%s) but not the target file/directory",
LOGGER.warn(() -> """
Deleting %s from location inside of temp dir (%s) \
to location outside of temp dir (%s) but not the target file/directory""".formatted(
linkType, file, realPath));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private ScheduledExecutorService getThreadExecutorForSameThreadInvocation() {
}

@SuppressWarnings({ "deprecation", "try" })
private static abstract class ExecutorResource implements Store.CloseableResource, AutoCloseable {
private abstract static class ExecutorResource implements Store.CloseableResource, AutoCloseable {

protected final ScheduledExecutorService executor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public static ThrowableCollector createThrowableCollector() {
return new OpenTest4JAndJUnit4AwareThrowableCollector();
}

private JupiterThrowableCollectorFactory() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ public static Type getGenericReturnType(Method method) {
}
return ReflectionSupport.invokeMethod(method, target, arguments);
}

private MethodReflectionUtils() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ public static UniqueId engineId() {
return UniqueId.forEngine(JupiterEngineDescriptor.ENGINE_ID);
}

private JupiterUniqueIdBuilder() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ private ArgumentCountValidationMode getArgumentCountValidationModeConfiguration(
return enumValue.get();
}
else {
logger.warn(() -> String.format(
"Invalid ArgumentCountValidationMode '%s' set via the '%s' configuration parameter. "
+ "Falling back to the %s default value.",
configValue, key, fallback.name()));
logger.warn(() -> """
Invalid ArgumentCountValidationMode '%s' set via the '%s' configuration parameter. \
Falling back to the %s default value.""".formatted(configValue, key, fallback.name()));
return fallback;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static ParameterizedInvocationNameFormatter create(ExtensionContext extensionCon
ParameterizedDeclarationContext<?> declarationContext) {

String name = declarationContext.getDisplayNamePattern();
String pattern = name.equals(DEFAULT_DISPLAY_NAME)
String pattern = DEFAULT_DISPLAY_NAME.equals(name)
? extensionContext.getConfigurationParameter(DISPLAY_NAME_PATTERN_KEY) //
.orElse(DEFAULT_DISPLAY_NAME_PATTERN)
: name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ private static <T> Constructor<?> findBestConstructor(Class<T> spiInterface,
}
}
// Otherwise...
String message = String.format(
"Failed to find constructor for %s [%s]. "
+ "Please ensure that a no-argument or a single constructor exists.",
String message = """
Failed to find constructor for %s [%s]. \
Please ensure that a no-argument or a single constructor exists.""".formatted(
spiInterface.getSimpleName(), implementationClass.getName());
throw new JUnitException(message);
}

private ParameterizedTestSpiInstantiator() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ private static ResolverFacade create(Executable executable, Annotation annotatio
Preconditions.condition(
aggregatorParameters.isEmpty()
|| aggregatorParameters.lastKey() == declaration.getParameterIndex() - 1,
() -> String.format(
"@%s %s declares formal parameters in an invalid order: "
+ "argument aggregators must be declared after any indexed arguments "
+ "and before any arguments resolved by another ParameterResolver.",
() -> """
@%s %s declares formal parameters in an invalid order: \
argument aggregators must be declared after any indexed arguments \
and before any arguments resolved by another ParameterResolver.""".formatted(
annotation.annotationType().getSimpleName(),
DefaultParameterDeclarations.describe(executable)));
aggregatorParameters.put(declaration.getParameterIndex(), declaration);
Expand Down
Loading