Skip to content

Commit bf09a7c

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

13 files changed

Lines changed: 80 additions & 10 deletions

File tree

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

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) {

platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/LocalMavenRepo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public String toCliArgument() {
6969
@Override
7070
public void close() throws IOException {
7171
try (var files = Files.walk(tempDir)) {
72-
files.sorted(Comparator.<Path> naturalOrder().reversed()) //
72+
files.sorted(Comparator.reverseOrder()) //
7373
.forEach(path -> {
7474
try {
7575
Files.delete(path);

0 commit comments

Comments
 (0)