Skip to content

Commit dc7e4fb

Browse files
author
Vincent Potucek
committed
[openrewrite] add SanityCheck featuring tech.picnic.errorprone.refasterrules
1 parent 834e994 commit dc7e4fb

File tree

14 files changed

+84
-10
lines changed

14 files changed

+84
-10
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ jobs:
4949
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
5050
with:
5151
token: ${{ secrets.CODECOV_TOKEN }}
52+
- name: rewriteDryRun
53+
uses: ./.github/actions/main-build
54+
with:
55+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
56+
arguments: rewriteDryRun
5257

5358
Windows:
5459
runs-on: windows-latest

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id("junitbuild.jacoco-aggregation-conventions")
88
id("junitbuild.maven-central-publishing")
99
id("junitbuild.temp-maven-repo")
10+
id("org.openrewrite.rewrite") version "7.17.0" apply false
1011
}
1112

1213
description = "JUnit"
@@ -54,3 +55,5 @@ dependencies {
5455
jacocoAggregation(projects.jupiterTests)
5556
jacocoAggregation(projects.platformTests)
5657
}
58+
59+
apply(from = "$rootDir/gradle/rewrite.gradle")

gradle/rewrite.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apply plugin: "org.openrewrite.rewrite"
2+
3+
rewrite {
4+
activeRecipe("org.junit.jupiter.openrewrite.SanityCheck")
5+
exportDatatables = true
6+
failOnDryRunResults = true
7+
}
8+
9+
dependencies {
10+
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.15.0"))
11+
rewrite("org.openrewrite.recipe:rewrite-java-security:3.19.0")
12+
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.18.0")
13+
rewrite("org.openrewrite.recipe:rewrite-rewrite:0.13.0")
14+
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.18.0")
15+
rewrite("org.openrewrite.recipe:rewrite-third-party:0.28.0")
16+
}

junit-platform-engine/src/main/java/org/junit/platform/engine/UniqueId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private UniqueId(UniqueIdFormat uniqueIdFormat, Segment segment) {
110110
}
111111

112112
Optional<Segment> getRoot() {
113-
return this.segments.isEmpty() ? Optional.empty() : Optional.of(this.segments.get(0));
113+
return this.segments.stream().findFirst();
114114
}
115115

116116
/**

junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/DefaultParallelExecutionConfigurationStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public ParallelExecutionConfiguration createConfiguration(ConfigurationParameter
6666
BigDecimal factor = configurationParameters.get(CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME,
6767
BigDecimal::new).orElse(BigDecimal.ONE);
6868

69-
Preconditions.condition(factor.compareTo(BigDecimal.ZERO) > 0,
69+
Preconditions.condition(factor.signum() == 1,
7070
() -> "Factor '%s' specified via configuration parameter '%s' must be greater than 0".formatted(factor,
7171
CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME));
7272

junit-platform-launcher/src/main/java/org/junit/platform/launcher/EngineFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public FilterResult apply(TestEngine testEngine) {
126126
Preconditions.notBlank(engineId, "TestEngine ID must not be null or blank");
127127

128128
if (this.type == Type.INCLUDE) {
129-
return includedIf(this.engineIds.stream().anyMatch(engineId::equals), //
129+
return includedIf(this.engineIds.contains(engineId), //
130130
() -> "Engine ID [%s] is in included list [%s]".formatted(engineId, this.engineIds), //
131131
() -> "Engine ID [%s] is not in included list [%s]".formatted(engineId, this.engineIds));
132132
}

junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static boolean containsFilesWithExtensions(Path dir, String... extension
140140
return false;
141141
};
142142
try (Stream<Path> pathStream = Files.find(dir, 1, matcher)) {
143-
return pathStream.findFirst().isPresent();
143+
return pathStream.findAny().isPresent();
144144
}
145145
}
146146
}

jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/predicates/IsTestFactoryMethodTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Collection rawCollectionFactory() {
174174

175175
@TestFactory
176176
Stream<?> unboundStreamFactory() {
177-
return Stream.of();
177+
return Stream.empty();
178178
}
179179

180180
}

platform-tests/src/test/java/org/junit/platform/commons/support/conversion/ConversionSupportTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void convertsStringToURL() throws Exception {
268268
@Test
269269
void convertsStringsToJavaTimeInstances() {
270270
assertConverts("PT1234.5678S", Duration.class, Duration.ofSeconds(1234, 567800000));
271-
assertConverts("1970-01-01T00:00:00Z", Instant.class, Instant.ofEpochMilli(0));
271+
assertConverts("1970-01-01T00:00:00Z", Instant.class, Instant.EPOCH);
272272
assertConverts("2017-03-14", LocalDate.class, LocalDate.of(2017, 3, 14));
273273
assertConverts("2017-03-14T12:34:56.789", LocalDateTime.class,
274274
LocalDateTime.of(2017, 3, 14, 12, 34, 56, 789_000_000));

platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/AbstractTestSourceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private <T extends Serializable> void assertSerializable(T instance) {
6060
var serialized = serialize(instance);
6161
var deserialized = deserialize(serialized);
6262

63-
assertTrue(type.isAssignableFrom(deserialized.getClass()));
63+
assertTrue(type.isInstance(deserialized));
6464
assertEquals(instance, deserialized);
6565
}
6666
catch (Exception e) {

0 commit comments

Comments
 (0)