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
4 changes: 2 additions & 2 deletions documentation/src/test/java/example/ClassTemplateDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ void wellKnown() {
}

// end::user_guide[]
static
public
// tag::user_guide[]
public class MyClassTemplateInvocationContextProvider
Copy link
Owner Author

@Pankraz76 Pankraz76 Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcphilipp might be missing config alignment of check, but this shoes once again that convention is the best config, might consider rewrite migration dropping the config burden promoting into 1LOC being a dedicated recipe, fully maintained by the community.

static class MyClassTemplateInvocationContextProvider
// tag::custom_line_break[]
implements ClassTemplateInvocationContextProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class ParameterizedMigrationDemo {
// tag::before[]
@RunWith(Parameterized.class)
// end::before[]
static
public
// tag::before[]
public class JUnit4ParameterizedClassTests {
static class JUnit4ParameterizedClassTests {

@Parameterized.Parameters
public static Iterable<Object[]> data() {
Expand Down
26 changes: 13 additions & 13 deletions documentation/src/test/java/example/ParameterizedTestDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ void testWithArgumentsSource(String argument) {
}

// end::ArgumentsSource_example[]
static
public
// tag::ArgumentsProvider_example[]
public class MyArgumentsProvider implements ArgumentsProvider {
static class MyArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
Expand All @@ -375,9 +375,9 @@ void testWithArgumentsSourceWithConstructorInjection(String argument) {
assertNotNull(argument);
}

static
public
// tag::ArgumentsProviderWithConstructorInjection_example[]
public class MyArgumentsProviderWithConstructorInjection implements ArgumentsProvider {
static class MyArgumentsProviderWithConstructorInjection implements ArgumentsProvider {

private final TestInfo testInfo;

Expand Down Expand Up @@ -427,9 +427,9 @@ void testWithImplicitFallbackArgumentConversion(Book book) {
}

// end::implicit_fallback_conversion_example[]
static
public
// tag::implicit_fallback_conversion_example_Book[]
public class Book {
static class Book {

private final String title;

Expand Down Expand Up @@ -458,10 +458,10 @@ void testWithExplicitArgumentConversion(
}

// end::explicit_conversion_example[]
static
public
@SuppressWarnings({ "NullableProblems", "NullAway" })
// tag::explicit_conversion_example_ToStringArgumentConverter[]
public class ToStringArgumentConverter extends SimpleArgumentConverter {
static class ToStringArgumentConverter extends SimpleArgumentConverter {

@Override
protected Object convert(Object source, Class<?> targetType) {
Expand All @@ -474,10 +474,10 @@ protected Object convert(Object source, Class<?> targetType) {
}
// end::explicit_conversion_example_ToStringArgumentConverter[]

static
public
@SuppressWarnings({ "NullableProblems", "NullAway", "ConstantValue" })
// tag::explicit_conversion_example_TypedArgumentConverter[]
public class ToLengthArgumentConverter extends TypedArgumentConverter<String, Integer> {
static class ToLengthArgumentConverter extends TypedArgumentConverter<String, Integer> {

protected ToLengthArgumentConverter() {
super(String.class, Integer.class);
Expand Down Expand Up @@ -516,7 +516,7 @@ void testWithArgumentsAccessor(ArgumentsAccessor arguments) {
arguments.get(2, Gender.class),
arguments.get(3, LocalDate.class));

if (person.getFirstName().equals("Jane")) {
if ("Jane".equals(person.getFirstName())) {
assertEquals(Gender.F, person.getGender());
}
else {
Expand All @@ -540,9 +540,9 @@ void testWithArgumentsAggregator(@AggregateWith(PersonAggregator.class) Person p
}

// end::ArgumentsAggregator_example[]
static
public
// tag::ArgumentsAggregator_example_PersonAggregator[]
public class PersonAggregator extends SimpleArgumentsAggregator {
static class PersonAggregator extends SimpleArgumentsAggregator {
@Override
protected Person aggregateArguments(ArgumentsAccessor arguments, Class<?> targetType,
AnnotatedElementContext context, int parameterIndex) {
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/test/java/example/TestInfoDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ static void beforeAll(TestInfo testInfo) {

TestInfoDemo(TestInfo testInfo) {
String displayName = testInfo.getDisplayName();
assertTrue(displayName.equals("TEST 1") || displayName.equals("test2()"));
assertTrue("TEST 1".equals(displayName) || "test2()".equals(displayName));
}

@BeforeEach
void init(TestInfo testInfo) {
String displayName = testInfo.getDisplayName();
assertTrue(displayName.equals("TEST 1") || displayName.equals("test2()"));
assertTrue("TEST 1".equals(displayName) || "test2()".equals(displayName));
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/test/java/example/TestTemplateDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ void testTemplate(String fruit) {
}

// end::user_guide[]
static
public
// @formatter:off
// tag::user_guide[]
public class MyTestTemplateInvocationContextProvider
static class MyTestTemplateInvocationContextProvider
implements TestTemplateInvocationContextProvider {

@Override
Expand Down
2 changes: 1 addition & 1 deletion documentation/src/test/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
</Configuration>
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version = 6.0.0-SNAPSHOT
# We need more metaspace due to apparent memory leak in Asciidoctor/JRuby
org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.caching=true
# https://github.com/openrewrite/rewrite-gradle-plugin/issues/212
org.gradle.parallel=true
org.gradle.configuration-cache.parallel=true
org.gradle.java.installations.fromEnv=GRAALVM_HOME,JDK17,JDK21,JDK24,JDK25
Expand Down
66 changes: 66 additions & 0 deletions gradle/config/rewrite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#type: specs.openrewrite.org/v1beta/recipe
#name: org.junit.openrewrite.recipe.CodeCleanup
#displayName: Code cleanup
#description: Automatically cleanup code, e.g. remove unnecessary parentheses, simplify expressions.
#recipeList:
# - org.openrewrite.java.RemoveUnusedImports
# - org.openrewrite.staticanalysis.EqualsAvoidsNull
# - org.openrewrite.staticanalysis.ModifierOrder
# - org.junit.openrewrite.recipe.AddLicenseHeader
# - org.junit.openrewrite.recipe.Java21ForTests
# - org.openrewrite.java.format.AutoFormat
# - org.openrewrite.java.format.BlankLines
# - org.openrewrite.java.format.NormalizeFormat
# - org.openrewrite.java.format.NormalizeLineBreaks
# - org.openrewrite.java.format.RemoveTrailingWhitespace
# - org.openrewrite.java.format.Spaces
# - org.openrewrite.java.format.TabsAndIndents
# - org.openrewrite.java.format.WrappingAndBraces
# - org.openrewrite.java.migrate.UpgradeToJava17
# - org.openrewrite.java.testing.assertj.Assertj
# - org.openrewrite.java.testing.cleanup.AssertTrueNullToAssertNull
# - org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
# - org.openrewrite.java.testing.junit5.JUnit5BestPractices
# - org.openrewrite.staticanalysis.CodeCleanup
# - org.openrewrite.staticanalysis.CommonStaticAnalysis
# - org.openrewrite.staticanalysis.FinalizeLocalVariables
# - org.openrewrite.staticanalysis.MissingOverrideAnnotation
# - org.openrewrite.staticanalysis.RedundantFileCreation
# - org.openrewrite.staticanalysis.RemoveUnusedLocalVariables
# - org.openrewrite.staticanalysis.RemoveUnusedPrivateFields
# - org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods
# - org.openrewrite.staticanalysis.StringLiteralEquality
# - org.openrewrite.text.EndOfLineAtEndOfFile
#---
type: specs.openrewrite.org/v1beta/recipe
name: org.junit.openrewrite.recipe.AddLicenseHeader
displayName: AddLicenseHeader
recipeList:
- org.openrewrite.java.AddLicenseHeader:
licenseText: """
/*
* Copyright 2015-${CURRENT_YEAR} the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/
"""
---
type: specs.openrewrite.org/v1beta/recipe
name: org.junit.openrewrite.recipe.Java21ForTests
displayName: Java21ForTests
preconditions:
- org.openrewrite.java.search.IsLikelyTest
recipeList:
- org.openrewrite.java.migrate.UpgradeToJava21
---
type: specs.openrewrite.org/v1beta/style
name: org.junit.openrewrite.recipe.NoTabsNoStarImports
styleConfigs:
- org.openrewrite.java.style.TabsAndIndentsStyle:
useTabCharacter: false
- org.openrewrite.java.style.ImportLayoutStyle:
classCountToUseStarImport: 9999
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mockito-core = { module = "org.mockito:mockito-core" }
mockito-junit-jupiter = { module = "org.mockito:mockito-junit-jupiter" }
nohttp-checkstyle = { module = "io.spring.nohttp:nohttp-checkstyle", version = "0.0.11" }
nullaway = { module = "com.uber.nullaway:nullaway", version = "0.12.7" }
openrewrite-recipe-bom = { module = "org.openrewrite.recipe:rewrite-recipe-bom", version = "3.11.1" }
opentest4j = { module = "org.opentest4j:opentest4j", version.ref = "opentest4j" }
openTestReporting-cli = { module = "org.opentest4j.reporting:open-test-reporting-cli", version.ref = "openTestReporting" }
openTestReporting-events = { module = "org.opentest4j.reporting:open-test-reporting-events", version.ref = "openTestReporting" }
Expand Down Expand Up @@ -105,6 +106,7 @@ jreleaser = { id = "org.jreleaser", version = "1.19.0" }
# check if workaround in gradle.properties can be removed when updating
kotlin = { id = "org.jetbrains.kotlin.jvm", version = "2.2.0" }
nullaway = { id = "net.ltgt.nullaway", version = "2.2.0" }
openrewrite = { id = "org.openrewrite.rewrite", version = "7.10.0" }
plantuml = { id = "io.freefair.plantuml", version = "8.14" }
shadow = { id = "com.gradleup.shadow", version = "8.3.8" }
spotless = { id = "com.diffplug.spotless", version = "7.1.0" }
1 change: 1 addition & 0 deletions gradle/plugins/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation(libs.plugins.foojayResolver.markerCoordinates)
implementation(libs.plugins.jmh.markerCoordinates)
implementation(libs.plugins.nullaway.markerCoordinates)
implementation(libs.plugins.openrewrite.markerCoordinates)
implementation(libs.plugins.shadow.markerCoordinates)
implementation(libs.plugins.spotless.markerCoordinates)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import junitbuild.extensions.dependencyFromLibs
import junitbuild.extensions.isSnapshot
import org.gradle.plugins.ide.eclipse.model.Classpath
import org.gradle.plugins.ide.eclipse.model.Library
Expand All @@ -13,6 +14,46 @@ plugins {
id("junitbuild.build-parameters")
id("junitbuild.checkstyle-conventions")
id("junitbuild.jacoco-java-conventions")
id("org.openrewrite.rewrite")
}

rewrite {
activeRecipe("org.openrewrite.java.RemoveUnusedImports")
activeRecipe("org.openrewrite.java.testing.cleanup.AssertTrueNullToAssertNull")
activeRecipe("org.openrewrite.staticanalysis.EqualsAvoidsNull")
activeRecipe("org.openrewrite.staticanalysis.MissingOverrideAnnotation")
activeRecipe("org.openrewrite.staticanalysis.ModifierOrder")
activeRecipe("org.openrewrite.staticanalysis.RedundantFileCreation")
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods")
activeRecipe("org.openrewrite.text.EndOfLineAtEndOfFile")
configFile = file("config/rewrite.yml")
failOnDryRunResults = true
// activeRecipe("org.junit.openrewrite.recipe.AddLicenseHeader")
// activeRecipe("org.junit.openrewrite.recipe.Java21ForTests")
// activeRecipe("org.openrewrite.java.format.AutoFormat")
// activeRecipe("org.openrewrite.java.format.BlankLines")
// activeRecipe("org.openrewrite.java.format.NormalizeFormat")
// activeRecipe("org.openrewrite.java.format.NormalizeLineBreaks")
// activeRecipe("org.openrewrite.java.format.RemoveTrailingWhitespace")
// activeRecipe("org.openrewrite.java.format.Spaces")
// activeRecipe("org.openrewrite.java.format.TabsAndIndents")
// activeRecipe("org.openrewrite.java.format.WrappingAndBraces")
// activeRecipe("org.openrewrite.java.migrate.UpgradeToJava21")
// activeRecipe("org.openrewrite.java.testing.assertj.Assertj")
// activeRecipe("org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic")
// activeRecipe("org.openrewrite.java.testing.junit5.JUnit5BestPractices")
// activeRecipe("org.openrewrite.staticanalysis.CodeCleanup")
// activeRecipe("org.openrewrite.staticanalysis.CommonStaticAnalysis")
// activeRecipe("org.openrewrite.staticanalysis.FinalizeLocalVariables")
// activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedLocalVariables")
// activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateFields")
// activeRecipe("org.openrewrite.staticanalysis.StringLiteralEquality")
}

dependencies {
rewrite(platform(dependencyFromLibs("openrewrite-recipe-bom")))
rewrite("org.openrewrite.recipe:rewrite-migrate-java")
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks")
}

val mavenizedProjects: List<Project> by rootProject.extra
Expand Down Expand Up @@ -270,6 +311,9 @@ tasks {
checkstyleTest {
config = resources.text.fromFile(checkstyle.configDirectory.file("checkstyleTest.xml"))
}
check {
dependsOn(rewriteDryRun)
}
}

pluginManager.withPlugin("java-test-fixtures") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ spotless {
targetExclude("gradle/plugins/**/build/**")
leadingSpacesToTabs()
trimTrailingWhitespace()
endWithNewline()
}

format("documentation") {
target("*.adoc", "*.md", "src/**/*.adoc", "src/**/*.md")
trimTrailingWhitespace()
endWithNewline()
}

pluginManager.withPlugin("java") {
Expand All @@ -36,8 +34,6 @@ spotless {
val majorMinorVersion = "([0-9]+\\.[0-9]+).*".toRegex().matchEntire(fullVersion)!!.let { it.groups[1]!!.value }
eclipse(majorMinorVersion).configFile(javaFormatterConfigFile)
trimTrailingWhitespace()
endWithNewline()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rule of 3

Image

removeUnusedImports()
}

format("moduleDescriptor") {
Expand All @@ -46,7 +42,6 @@ spotless {
})
licenseHeaderFile(license.headerFile, "^$")
trimTrailingWhitespace()
endWithNewline()
}
}

Expand All @@ -56,7 +51,6 @@ spotless {
ktlint(requiredVersionFromLibs("ktlint"))
licenseHeaderFile(license.headerFile)
trimTrailingWhitespace()
endWithNewline()
}
configurations.named { it.startsWith("spotless") }.configureEach {
// Workaround for CVE-2024-12798 and CVE-2024-12801
Expand All @@ -74,7 +68,6 @@ spotless {
groovy {
licenseHeaderFile(license.headerFile)
trimTrailingWhitespace()
endWithNewline()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.junit.jupiter.engine.JupiterTestEngine
org.junit.jupiter.engine.JupiterTestEngine
Loading
Loading