Skip to content

Commit d489fa4

Browse files
author
Vincent Potucek
committed
Add CleanupAssertions junit-team#5193 junit-team#5002
- https://docs.openrewrite.org/recipes/java/testing/junit/jupiterbestpractices Signed-off-by: Vincent Potucek <vpotucek@me.com>
1 parent c9454e3 commit d489fa4

16 files changed

Lines changed: 226 additions & 145 deletions

.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.java.testing.junit5.CleanupAssertions
8+
# - org.openrewrite.java.testing.junit.JupiterBestPractices
9+
---

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ commonCustomUserData = { id = "com.gradle.common-custom-user-data-gradle-plugin"
9494
develocity = { id = "com.gradle.develocity", version = "4.2.2" }
9595
download = { id = "de.undercouch.download", version = "5.6.0" }
9696
errorProne = { id = "net.ltgt.errorprone", version = "4.3.0" }
97+
rewrite = { id = "org.openrewrite.rewrite", version = "7.22.0" }
9798
foojayResolver = { id = "org.gradle.toolchains.foojay-resolver", version = "1.0.0" }
9899
jmh = { id = "me.champeau.jmh", version = "0.7.3" }
99100
jreleaser = { id = "org.jreleaser", version = "1.21.0" }

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-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id("org.openrewrite.rewrite")
3+
}
4+
5+
dependencies {
6+
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks:3.23.0")
7+
}
8+
9+
rewrite {
10+
activeRecipe("org.junit.openrewrite.SanityCheck")
11+
configFile = project.getRootProject().file("gradle/config/rewrite.yml")
12+
exclusion(
13+
"**AssertionsTests.java", // AssertEqualsAssertionsTests > assertEqualsWithUnequalObjectWhoseToStringImplementationThrowsAnException() FAILED
14+
// legacy
15+
"**TestCase.java",
16+
"**TestCases.java",
17+
"**documentation/src/test/java/example**",
18+
"**testFixtures/java/org/junit/vintage/engine/samples**",
19+
)
20+
setExportDatatables(true)
21+
setFailOnDryRunResults(true)
22+
}

jupiter-tests/src/test/java/org/junit/jupiter/engine/TestClassInheritanceTests.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,21 @@ void beforeAndAfterMethodsInTestClassHierarchy() {
116116
// @formatter:on
117117

118118
// @formatter:off
119-
assertEquals(asList(
120-
"beforeAll1",
119+
assertEquals(callSequence, asList(
120+
"beforeAll1",
121121
"beforeAll2",
122-
"beforeAll3",
123-
"beforeEach1",
124-
"beforeEach2",
125-
"beforeEach3",
126-
"test3",
127-
"afterEach3",
128-
"afterEach2",
129-
"afterEach1",
130-
"afterAll3",
122+
"beforeAll3",
123+
"beforeEach1",
124+
"beforeEach2",
125+
"beforeEach3",
126+
"test3",
127+
"afterEach3",
128+
"afterEach2",
129+
"afterEach1",
130+
"afterAll3",
131131
"afterAll2",
132-
"afterAll1"
133-
), callSequence, "wrong call sequence");
132+
"afterAll1"
133+
), "wrong call sequence");
134134
// @formatter:on
135135
}
136136

jupiter-tests/src/test/java/org/junit/jupiter/engine/TestInstanceLifecycleConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private void performAssertions(Class<?> testClass, Map<String, String> configPar
138138
executionResults.testEvents().assertStatistics(//
139139
stats -> stats.started(numTests).finished(numTests));
140140

141-
assertEquals(Arrays.asList(methods), methodsInvoked);
141+
assertEquals(methodsInvoked, Arrays.asList(methods));
142142
}
143143

144144
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)