Skip to content

Commit 4c1138f

Browse files
author
Vincent Potucek
committed
Add org.junit.openrewrite.SanityCheck
enabler for: - https://docs.openrewrite.org/recipes/java/testing/junit/jupiterbestpractices Signed-off-by: Vincent Potucek <vpotucek@me.com>
1 parent dbbacd6 commit 4c1138f

File tree

20 files changed

+160
-37
lines changed

20 files changed

+160
-37
lines changed

.github/workflows/sanity-check.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Sanity Check 🕊
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- 'releases/**'
7+
paths:
8+
- '.github/**'
9+
pull_request:
10+
paths:
11+
- '.github/**'
12+
permissions: {}
13+
jobs:
14+
validate:
15+
name: Validate 📊
16+
runs-on: ubuntu-latest
17+
permissions:
18+
security-events: write
19+
steps:
20+
- name: Checkout Repository 📥
21+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
22+
with:
23+
persist-credentials: false
24+
- name: Checkstyle ☑️
25+
uses: ./.github/actions/run-gradle
26+
with:
27+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
28+
arguments: checkstyleMain
29+
- name: Spotless ✨
30+
uses: ./.github/actions/run-gradle
31+
with:
32+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
33+
arguments: spotlessCheck
34+
- name: ArchUnit 🏛️
35+
uses: ./.github/actions/run-gradle
36+
with:
37+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
38+
arguments: archUnit
39+
- name: OSGi 🧩
40+
uses: ./.github/actions/run-gradle
41+
with:
42+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
43+
arguments: verifyOSGiTask
44+
- name: Rewrite ⚙️
45+
uses: ./.github/actions/run-gradle
46+
with:
47+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
48+
arguments: rewriteDryRun -Dorg.gradle.jvmargs=-Xmx2G

gradle/config/rewrite.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
type: specs.openrewrite.org/v1beta/recipe
3+
name: org.junit.openrewrite.SanityCheck
4+
displayName: Apply all common best practices
5+
description: Comprehensive code quality recipe combining modernization, security, and best practices.
6+
recipeList:
7+
- org.openrewrite.staticanalysis.EqualsAvoidsNull
8+
- tech.picnic.errorprone.refasterrules.TimeRulesRecipes
9+
---

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ commonCustomUserData = { id = "com.gradle.common-custom-user-data-gradle-plugin"
101101
develocity = { id = "com.gradle.develocity", version = "4.2.2" }
102102
download = { id = "de.undercouch.download", version = "5.6.0" }
103103
errorProne = { id = "net.ltgt.errorprone", version = "4.3.0" }
104+
rewrite = { id = "org.openrewrite.rewrite", version = "7.21.0" }
104105
foojayResolver = { id = "org.gradle.toolchains.foojay-resolver", version = "1.0.0" }
105106
gitPublish = { id = "org.ajoberstar.git-publish", version = "5.1.3" }
106107
jmh = { id = "me.champeau.jmh", version = "0.7.3" }

gradle/plugins/common/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ plugins {
77

88
dependencies {
99
implementation("junitbuild.base:dsl-extensions")
10-
implementation(projects.buildParameters)
1110
implementation(projects.backwardCompatibility)
12-
implementation(libs.plugins.kotlin.markerCoordinates)
11+
implementation(projects.buildParameters)
1312
implementation(libs.plugins.bnd.markerCoordinates)
1413
implementation(libs.plugins.commonCustomUserData.markerCoordinates)
1514
implementation(libs.plugins.develocity.markerCoordinates)
1615
implementation(libs.plugins.errorProne.markerCoordinates)
1716
implementation(libs.plugins.foojayResolver.markerCoordinates)
1817
implementation(libs.plugins.jmh.markerCoordinates)
18+
implementation(libs.plugins.kotlin.markerCoordinates)
1919
implementation(libs.plugins.nullaway.markerCoordinates)
20+
implementation(libs.plugins.rewrite.markerCoordinates)
2021
implementation(libs.plugins.shadow.markerCoordinates)
2122
implementation(libs.plugins.spotless.markerCoordinates)
2223
}

gradle/plugins/common/src/main/kotlin/junitbuild.checkstyle-conventions.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,3 @@ checkstyle {
2020
toolVersion = requiredVersionFromLibs("checkstyle")
2121
configDirectory = rootProject.layout.projectDirectory.dir("gradle/config/checkstyle")
2222
}
23-
24-
tasks.check {
25-
dependsOn(tasks.withType<Checkstyle>())
26-
}

gradle/plugins/common/src/main/kotlin/junitbuild.java-errorprone-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tasks.withType<JavaCompile>().configureEach {
4545
error(
4646
"CanonicalAnnotationSyntax",
4747
"IsInstanceLambdaUsage",
48+
"TryWithResourcesVariable",
4849
"PackageLocation",
4950
"RedundantStringConversion",
5051
"RedundantStringEscape",

gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99
id("junitbuild.eclipse-conventions")
1010
id("junitbuild.jacoco-java-conventions")
1111
id("junitbuild.java-errorprone-conventions")
12+
id("junitbuild.rewrite-conventions")
1213
}
1314

1415
val mavenizedProjects: List<Project> by rootProject.extra

gradle/plugins/common/src/main/kotlin/junitbuild.osgi-conventions.gradle.kts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,21 @@ val osgiVerificationClasspath = configurations.resolvable("osgiVerificationClass
9999
extendsFrom(osgiVerification.get())
100100
}
101101

102+
// Make the task available for calling from outside
103+
tasks.register("verifyOSGiTask") {
104+
description = "Verifies OSGi metadata in the built jar"
105+
group = "verification"
106+
dependsOn(verify)
107+
}
108+
102109
// Bnd's Resolve task is what verifies that a jar can be used in OSGi and
103110
// that its metadata is valid. If the metadata is invalid this task will
104111
// fail.
105-
val verifyOSGi by tasks.registering(Resolve::class) {
112+
val verify by tasks.registering(Resolve::class) {
106113
bndrun = osgiProperties.flatMap { it.destinationFile }
107114
outputBndrun = layout.buildDirectory.file("resolvedOSGiProperties.bndrun")
108115
isReportOptional = false
109-
// By default bnd will use jars found in:
116+
// By default, bnd will use jars found in:
110117
// 1. project.sourceSets.main.runtimeClasspath
111118
// 2. project.configurations.archives.artifacts.files
112119
// to validate the metadata.
@@ -116,7 +123,3 @@ val verifyOSGi by tasks.registering(Resolve::class) {
116123
bundles(osgiVerificationClasspath)
117124
properties.empty()
118125
}
119-
120-
tasks.check {
121-
dependsOn(verifyOSGi)
122-
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
plugins {
2+
id("org.openrewrite.rewrite")
3+
}
4+
5+
dependencies {
6+
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.22.0")
7+
}
8+
9+
rewrite {
10+
activeRecipe("org.junit.openrewrite.SanityCheck")
11+
configFile = project.getRootProject().file("gradle/config/rewrite.yml")
12+
exclusion(
13+
// JupiterBestPractices: class scope issue;
14+
"**AggregatorIntegrationTests.java",
15+
"**BeforeAndAfterSuiteTests.java",
16+
"**BridgeMethods.java",
17+
"**CsvArgumentsProvider.java",
18+
"**DefaultArgumentsAccessor.java",
19+
"**DiscoverySelectorResolverTests.java",
20+
"**DiscoveryTests.java",
21+
"**DisplayNameGenerationTests.java",
22+
"**DynamicNodeGenerationTests.java",
23+
"**DynamicTestTests.java",
24+
"**EngineDiscoveryResultValidatorTests.java", // fixable with @DisabledOnOs(WINDOWS)
25+
"**ExceptionHandlingTests.java",
26+
"**ExecutionCancellationTests.java",
27+
"**ExtensionRegistrationViaParametersAndFieldsTests.java",
28+
"**InvocationInterceptorTests.java",
29+
"**IsTestMethodTests.java",
30+
"**IsTestTemplateMethodTests.java",
31+
"**JupiterTestDescriptorTests.java",
32+
"**LifecycleMethodUtilsTests.java",
33+
"**MultipleTestableAnnotationsTests.java",
34+
"**NestedContainerEventConditionTests.java",
35+
"**ParallelExecutionIntegrationTests.java",
36+
"**ParameterResolverTests.java",
37+
"**ParameterizedTestIntegrationTests.java",
38+
"**RepeatedTestTests.java",
39+
"**StaticPackagePrivateBeforeMethod.java",
40+
"**SubclassedAssertionsTests.java",
41+
"**TempDirectoryCleanupTests.java",
42+
"**TestCase.java",
43+
"**TestCases.java",
44+
"**TestExecutionExceptionHandlerTests.java",
45+
"**TestInstanceFactoryTests.java",
46+
"**TestTemplateInvocationTestDescriptorTests.java",
47+
"**TestTemplateInvocationTests.java",
48+
"**TestTemplateTestDescriptorTests.java",
49+
"**TestWatcherTests.java",
50+
"**TimeoutExtensionTests.java",
51+
"**UniqueIdTrackingListenerIntegrationTests.java",
52+
"**WorkerThreadPoolHierarchicalTestExecutorServiceTests.java",
53+
"**org/junit/jupiter/engine/bridge**",
54+
// trivial import fix.
55+
"**Assert**AssertionsTests.java",
56+
"**DynamicContainerTests.java",
57+
// legacy
58+
"**documentation/src/test/java/example**",
59+
"**testFixtures/java/org/junit/vintage/engine/samples**",
60+
)
61+
setExportDatatables(true)
62+
setFailOnDryRunResults(true)
63+
}

jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterEachTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void beforeEachMethodThrowsAnException() {
231231
);
232232
// @formatter:on
233233

234-
List<String> expected = beforeEachMethodCallSequence.getFirst().equals("beforeEachMethod1") ? list1 : list2;
234+
List<String> expected = "beforeEachMethod1".equals(beforeEachMethodCallSequence.getFirst()) ? list1 : list2;
235235

236236
assertEquals(expected, callSequence, "wrong call sequence");
237237

0 commit comments

Comments
 (0)