Skip to content
Open
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
48 changes: 48 additions & 0 deletions .github/workflows/sanity-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Sanity Check 🕊
on:
push:
branches:
- main
- 'releases/**'
paths:
- '.github/**'
pull_request:
paths:
- '.github/**'
permissions: {}
jobs:
validate:
name: Validate 📊
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Checkout Repository 📥
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
persist-credentials: false
- name: Checkstyle ☑️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: checkstyleMain
- name: Spotless ✨
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: spotlessCheck
- name: ArchUnit 🏛️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: archUnit
- name: OSGi 🧩
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: verifyOSGiTask
- name: Rewrite ⚙️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: rewriteDryRun -Dorg.gradle.jvmargs=-Xmx2G
9 changes: 9 additions & 0 deletions gradle/config/rewrite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
type: specs.openrewrite.org/v1beta/recipe
name: org.junit.openrewrite.SanityCheck
displayName: Apply all common best practices
description: Comprehensive code quality recipe combining modernization, security, and best practices.
recipeList:
- org.openrewrite.staticanalysis.EqualsAvoidsNull
- tech.picnic.errorprone.refasterrules.TimeRulesRecipes
---
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ commonCustomUserData = { id = "com.gradle.common-custom-user-data-gradle-plugin"
develocity = { id = "com.gradle.develocity", version = "4.2.2" }
download = { id = "de.undercouch.download", version = "5.6.0" }
errorProne = { id = "net.ltgt.errorprone", version = "4.3.0" }
rewrite = { id = "org.openrewrite.rewrite", version = "7.21.0" }
foojayResolver = { id = "org.gradle.toolchains.foojay-resolver", version = "1.0.0" }
gitPublish = { id = "org.ajoberstar.git-publish", version = "5.1.3" }
jmh = { id = "me.champeau.jmh", version = "0.7.3" }
Expand Down
5 changes: 3 additions & 2 deletions gradle/plugins/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ plugins {

dependencies {
implementation("junitbuild.base:dsl-extensions")
implementation(projects.buildParameters)
implementation(projects.backwardCompatibility)
implementation(libs.plugins.kotlin.markerCoordinates)
implementation(projects.buildParameters)
implementation(libs.plugins.bnd.markerCoordinates)
implementation(libs.plugins.commonCustomUserData.markerCoordinates)
implementation(libs.plugins.develocity.markerCoordinates)
implementation(libs.plugins.errorProne.markerCoordinates)
implementation(libs.plugins.foojayResolver.markerCoordinates)
implementation(libs.plugins.jmh.markerCoordinates)
implementation(libs.plugins.kotlin.markerCoordinates)
implementation(libs.plugins.nullaway.markerCoordinates)
implementation(libs.plugins.rewrite.markerCoordinates)
implementation(libs.plugins.shadow.markerCoordinates)
implementation(libs.plugins.spotless.markerCoordinates)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ checkstyle {
toolVersion = requiredVersionFromLibs("checkstyle")
configDirectory = rootProject.layout.projectDirectory.dir("gradle/config/checkstyle")
}

tasks.check {
dependsOn(tasks.withType<Checkstyle>())
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ tasks.withType<JavaCompile>().configureEach {
error(
"CanonicalAnnotationSyntax",
"IsInstanceLambdaUsage",
"TryWithResourcesVariable",
"PackageLocation",
"RedundantStringConversion",
"RedundantStringEscape",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id("junitbuild.eclipse-conventions")
id("junitbuild.jacoco-java-conventions")
id("junitbuild.java-errorprone-conventions")
id("junitbuild.rewrite-conventions")
}

val mavenizedProjects: List<Project> by rootProject.extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,21 @@ val osgiVerificationClasspath = configurations.resolvable("osgiVerificationClass
extendsFrom(osgiVerification.get())
}

// Make the task available for calling from outside
tasks.register("verifyOSGiTask") {
description = "Verifies OSGi metadata in the built jar"
group = "verification"
dependsOn(verify)
}

// Bnd's Resolve task is what verifies that a jar can be used in OSGi and
// that its metadata is valid. If the metadata is invalid this task will
// fail.
val verifyOSGi by tasks.registering(Resolve::class) {
val verify by tasks.registering(Resolve::class) {
bndrun = osgiProperties.flatMap { it.destinationFile }
outputBndrun = layout.buildDirectory.file("resolvedOSGiProperties.bndrun")
isReportOptional = false
// By default bnd will use jars found in:
// By default, bnd will use jars found in:
// 1. project.sourceSets.main.runtimeClasspath
// 2. project.configurations.archives.artifacts.files
// to validate the metadata.
Expand All @@ -116,7 +123,3 @@ val verifyOSGi by tasks.registering(Resolve::class) {
bundles(osgiVerificationClasspath)
properties.empty()
}

tasks.check {
dependsOn(verifyOSGi)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
plugins {
id("org.openrewrite.rewrite")
}

dependencies {
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.22.0")
}

rewrite {
activeRecipe("org.junit.openrewrite.SanityCheck")
configFile = project.getRootProject().file("gradle/config/rewrite.yml")
exclusion(
// JupiterBestPractices: class scope issue;
"**AggregatorIntegrationTests.java",
"**BeforeAndAfterSuiteTests.java",
"**BridgeMethods.java",
"**CsvArgumentsProvider.java",
"**DefaultArgumentsAccessor.java",
"**DiscoverySelectorResolverTests.java",
"**DiscoveryTests.java",
"**DisplayNameGenerationTests.java",
"**DynamicNodeGenerationTests.java",
"**DynamicTestTests.java",
"**EngineDiscoveryResultValidatorTests.java", // fixable with @DisabledOnOs(WINDOWS)
"**ExceptionHandlingTests.java",
"**ExecutionCancellationTests.java",
"**ExtensionRegistrationViaParametersAndFieldsTests.java",
"**InvocationInterceptorTests.java",
"**IsTestMethodTests.java",
"**IsTestTemplateMethodTests.java",
"**JupiterTestDescriptorTests.java",
"**LifecycleMethodUtilsTests.java",
"**MultipleTestableAnnotationsTests.java",
"**NestedContainerEventConditionTests.java",
"**ParallelExecutionIntegrationTests.java",
"**ParameterResolverTests.java",
"**ParameterizedTestIntegrationTests.java",
"**RepeatedTestTests.java",
"**StaticPackagePrivateBeforeMethod.java",
"**SubclassedAssertionsTests.java",
"**TempDirectoryCleanupTests.java",
"**TestCase.java",
"**TestCases.java",
"**TestExecutionExceptionHandlerTests.java",
"**TestInstanceFactoryTests.java",
"**TestTemplateInvocationTestDescriptorTests.java",
"**TestTemplateInvocationTests.java",
"**TestTemplateTestDescriptorTests.java",
"**TestWatcherTests.java",
"**TimeoutExtensionTests.java",
"**UniqueIdTrackingListenerIntegrationTests.java",
"**WorkerThreadPoolHierarchicalTestExecutorServiceTests.java",
"**org/junit/jupiter/engine/bridge**",
// trivial import fix.
"**Assert**AssertionsTests.java",
"**DynamicContainerTests.java",
// legacy
"**documentation/src/test/java/example**",
"**testFixtures/java/org/junit/vintage/engine/samples**",
)
setExportDatatables(true)
setFailOnDryRunResults(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void beforeEachMethodThrowsAnException() {
);
// @formatter:on

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static abstract class AbstractTestInstancePreConstructCallback implements TestIn
public void preConstructTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext context) {
assertThat(context.getTestInstance()).isNotPresent();
assertThat(context.getTestClass()).isPresent();
if (name.equals("legacy")) {
if ("legacy".equals(name)) {
assertThat(factoryContext.getTestClass()).isSameAs(context.getTestClass().get());
}
else if (context.getTestInstanceLifecycle().orElse(null) != TestInstance.Lifecycle.PER_CLASS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ static Stream<String> parameters() {

@Test
void test() {
assertTrue(value.equals("foo") || value.equals("bar"));
assertTrue("foo".equals(value) || "bar".equals(value));
}
}

Expand All @@ -1213,7 +1213,7 @@ static Stream<String> parameters() {

@Test
void test() {
assertTrue(value.equals("foo") || value.equals("bar"));
assertTrue("foo".equals(value) || "bar".equals(value));
}
}

Expand All @@ -1235,7 +1235,7 @@ record FieldSourceConstructorInjectionTestCase(String value) {

@Test
void test() {
assertTrue(value.equals("foo") || value.equals("bar"));
assertTrue("foo".equals(value) || "bar".equals(value));
}
}

Expand All @@ -1250,7 +1250,7 @@ static class FieldSourceFieldInjectionTestCase {

@Test
void test() {
assertTrue(value.equals("foo") || value.equals("bar"));
assertTrue("foo".equals(value) || "bar".equals(value));
}
}

Expand All @@ -1269,7 +1269,7 @@ void test() {
record ArgumentsSourceConstructorInjectionTestCase(String value) {
@Test
void test() {
assertTrue(value.equals("foo") || value.equals("bar"));
assertTrue("foo".equals(value) || "bar".equals(value));
}
}

Expand All @@ -1282,7 +1282,7 @@ static class ArgumentsSourceFieldInjectionTestCase {

@Test
void test() {
assertTrue(value.equals("foo") || value.equals("bar"));
assertTrue("foo".equals(value) || "bar".equals(value));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void emptyDisplayNameIsIllegal() {
void defaultDisplayNameWithEmptyStringInConfigurationIsIllegal() {
AtomicInteger invocations = new AtomicInteger();
Function<String, Optional<String>> configurationSupplier = key -> {
if (key.equals(ParameterizedInvocationNameFormatter.DISPLAY_NAME_PATTERN_KEY)) {
if (ParameterizedInvocationNameFormatter.DISPLAY_NAME_PATTERN_KEY.equals(key)) {
invocations.incrementAndGet();
return Optional.of("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void convertsStringToURL() throws Exception {
@Test
void convertsStringsToJavaTimeInstances() {
assertConverts("PT1234.5678S", Duration.class, Duration.ofSeconds(1234, 567800000));
assertConverts("1970-01-01T00:00:00Z", Instant.class, Instant.ofEpochMilli(0));
assertConverts("1970-01-01T00:00:00Z", Instant.class, Instant.EPOCH);
assertConverts("2017-03-14", LocalDate.class, LocalDate.of(2017, 3, 14));
assertConverts("2017-03-14T12:34:56.789", LocalDateTime.class,
LocalDateTime.of(2017, 3, 14, 12, 34, 56, 789_000_000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void assertClassesScannedWhenExceptionIsThrown(Predicate<Class<?>> filte
@Test
void scanForResourcesInClasspathRootWhenGenericRuntimeExceptionOccurs(LogRecordListener listener) throws Exception {
Predicate<Resource> runtimeExceptionSimulationFilter = resource -> {
if (resource.getName().equals("org/junit/platform/commons/other-example.resource")) {
if ("org/junit/platform/commons/other-example.resource".equals(resource.getName())) {
throw new RuntimeException("a generic exception");
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
*/
class ReflectionUtilsTests {

private static final Predicate<Method> isFooMethod = method -> method.getName().equals("foo");
private static final Predicate<Method> isFooMethod = method -> "foo".equals(method.getName());
private static final Predicate<Method> methodContains1 = method -> method.getName().contains("1");
private static final Predicate<Method> methodContains2 = method -> method.getName().contains("2");
private static final Predicate<Method> methodContains4 = method -> method.getName().contains("4");
Expand Down Expand Up @@ -1270,7 +1270,7 @@ void isMethodPresentPreconditions() {

@Test
void isMethodPresent() {
Predicate<Method> isMethod1 = method -> (method.getName().equals("method1")
Predicate<Method> isMethod1 = method -> ("method1".equals(method.getName())
&& method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == String.class);

assertThat(ReflectionUtils.isMethodPresent(MethodShadowingChild.class, isMethod1)).isTrue();
Expand Down Expand Up @@ -1504,7 +1504,7 @@ private static void assertOneFooMethodIn(Class<?> clazz) {
*/
@Test
void findMethodsFindsDistinctMethodsDeclaredInMultipleInterfaces() {
Predicate<Method> isStringsMethod = method -> method.getName().equals("strings");
Predicate<Method> isStringsMethod = method -> "strings".equals(method.getName());
assertThat(findMethods(DoubleInheritedInterfaceMethodTestCase.class, isStringsMethod)).hasSize(1);
}

Expand Down Expand Up @@ -1551,10 +1551,10 @@ void findMethodsUsingHierarchyUpMode() throws Exception {
.containsExactly(ChildClass.class.getMethod("otherMethod3"),
ParentClass.class.getMethod("otherMethod2"), GrandparentClass.class.getMethod("otherMethod1"));

assertThat(findMethods(ChildClass.class, method -> method.getName().equals("method2"), BOTTOM_UP))//
assertThat(findMethods(ChildClass.class, method -> "method2".equals(method.getName()), BOTTOM_UP))//
.containsExactly(ParentClass.class.getMethod("method2"));

assertThat(findMethods(ChildClass.class, method -> method.getName().equals("wrongName"), BOTTOM_UP))//
assertThat(findMethods(ChildClass.class, method -> "wrongName".equals(method.getName()), BOTTOM_UP))//
.isEmpty();

assertThat(findMethods(ParentClass.class, method -> method.getName().contains("method"), BOTTOM_UP))//
Expand All @@ -1573,10 +1573,10 @@ void findMethodsUsingHierarchyDownMode() throws Exception {
.containsExactly(GrandparentClass.class.getMethod("otherMethod1"),
ParentClass.class.getMethod("otherMethod2"), ChildClass.class.getMethod("otherMethod3"));

assertThat(findMethods(ChildClass.class, method -> method.getName().equals("method2"), TOP_DOWN))//
assertThat(findMethods(ChildClass.class, method -> "method2".equals(method.getName()), TOP_DOWN))//
.containsExactly(ParentClass.class.getMethod("method2"));

assertThat(findMethods(ChildClass.class, method -> method.getName().equals("wrongName"), TOP_DOWN))//
assertThat(findMethods(ChildClass.class, method -> "wrongName".equals(method.getName()), TOP_DOWN))//
.isEmpty();

assertThat(findMethods(ParentClass.class, method -> method.getName().contains("method"), TOP_DOWN))//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId
inOrder.verify(executionListener).executionStarted(
argThat(d -> d.getUniqueIdObject().equals(UniqueId.forEngine("engine-id"))));
inOrder.verify(executionListener).executionSkipped(
argThat(d -> d.getUniqueIdObject().getLastSegment().getType().equals("container")),
argThat(d -> "container".equals(d.getUniqueIdObject().getLastSegment().getType())),
eq("Execution cancelled"));
inOrder.verify(executionListener).executionFinished(
argThat(d -> d.getUniqueIdObject().equals(UniqueId.forEngine("engine-id"))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ static void prepareLocalLibraryDirectoryWithJUnitModules() throws Exception {
}
for (var module : Helper.loadModuleDirectoryNames()) {
if (module.startsWith("junit-platform") || module.startsWith("junit-jupiter")
|| module.equals("junit-start")) {
if (module.equals("junit-jupiter-migrationsupport"))
|| "junit-start".equals(module)) {
if ("junit-jupiter-migrationsupport".equals(module))
continue;
if (module.startsWith("junit-platform-suite"))
continue;
if (module.equals("junit-platform-testkit"))
if ("junit-platform-testkit".equals(module))
continue;
var jar = MavenRepo.jar(module);
Files.copy(jar, lib.resolve(module + ".jar"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void manifestEntriesAdhereToConventions(String module) throws Exception {
assertValue(attributes, "Bundle-SymbolicName", module);
assertValue(attributes, "Bundle-Version",
MavenVersion.parseMavenString(version).getOSGiVersion().toString());
if (module.equals("junit-platform-console")) {
if ("junit-platform-console".equals(module)) {
assertValue(attributes, "Main-Class", "org.junit.platform.console.ConsoleLauncher");
}
var domain = Domain.domain(manifest);
Expand Down
Loading