From 370928a2f513f9c89a40ca06054890c517b3622a Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Mon, 8 Nov 2021 11:59:39 +0100 Subject: [PATCH] StaticImport: Add WebEnvironment enum Assorted upgrades and add license `BSD License 3` --- error-prone-contrib/pom.xml | 5 +++++ .../bugpatterns/StaticImportCheck.java | 1 + .../bugpatterns/StaticImportCheckTest.java | 18 ++++++++++++++++++ pom.xml | 10 ++++++++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 8d71bb4b6ca..56021df1d57 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -186,6 +186,11 @@ spring-webflux provided + + org.springframework.boot + spring-boot-test + provided + org.testng testng diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImportCheck.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImportCheck.java index b0efa3dedb9..5a5eb982087 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImportCheck.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImportCheck.java @@ -80,6 +80,7 @@ public final class StaticImportCheck extends BugChecker implements MemberSelectT "org.mockito.Answers", "org.mockito.ArgumentMatchers", "org.mockito.Mockito", + "org.springframework.boot.test.context.SpringBootTest.WebEnvironment", "org.springframework.format.annotation.DateTimeFormat.ISO", "org.springframework.http.HttpHeaders", "org.springframework.http.HttpMethod", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportCheckTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportCheckTest.java index ee6520dc646..d8d0c3ccd15 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportCheckTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportCheckTest.java @@ -27,6 +27,7 @@ void identification() { "import static com.google.common.collect.ImmutableSet.toImmutableSet;", "import static java.nio.charset.StandardCharsets.UTF_8;", "import static java.util.function.Predicate.not;", + "import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;", "", "import com.google.common.base.Predicates;", "import com.google.common.collect.ImmutableMap;", @@ -35,6 +36,8 @@ void identification() { "import java.nio.charset.StandardCharsets;", "import java.util.Optional;", "import java.util.function.Predicate;", + "import org.springframework.boot.test.context.SpringBootTest;", + "import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;", "", "class A {", " void m() {", @@ -68,6 +71,10 @@ void identification() { " Object o1 = StandardCharsets.UTF_8;", " Object o2 = UTF_8;", "", + " // BUG: Diagnostic contains:", + " WebEnvironment randomPort1 = WebEnvironment.RANDOM_PORT;", + " WebEnvironment randomPort2 = RANDOM_PORT;", + "", " Optional.empty();", " }", "", @@ -89,6 +96,8 @@ void replacement() { "import java.nio.charset.StandardCharsets;", "import org.springframework.format.annotation.DateTimeFormat;", "import org.springframework.format.annotation.DateTimeFormat.ISO;", + "import org.springframework.boot.test.context.SpringBootTest;", + "import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;", "", "class A {", " void m1() {", @@ -113,6 +122,9 @@ void replacement() { " @DateTimeFormat(iso = ISO.DATE) String date,", " @DateTimeFormat(iso = ISO.DATE_TIME) String dateTime,", " @DateTimeFormat(iso = ISO.TIME) String time) {}", + "", + " @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)", + " final class Foo {}", "}") .addOutputLines( "out/A.java", @@ -120,6 +132,7 @@ void replacement() { "import static com.google.common.collect.ImmutableSet.toImmutableSet;", "import static java.nio.charset.StandardCharsets.UTF_8;", "import static java.util.function.Predicate.not;", + "import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;", "import static org.springframework.format.annotation.DateTimeFormat.ISO.DATE;", "import static org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME;", "import static org.springframework.format.annotation.DateTimeFormat.ISO.TIME;", @@ -128,6 +141,8 @@ void replacement() { "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableSet;", "import java.nio.charset.StandardCharsets;", + "import org.springframework.boot.test.context.SpringBootTest;", + "import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;", "import org.springframework.format.annotation.DateTimeFormat;", "import org.springframework.format.annotation.DateTimeFormat.ISO;", "", @@ -154,6 +169,9 @@ void replacement() { " @DateTimeFormat(iso = DATE) String date,", " @DateTimeFormat(iso = DATE_TIME) String dateTime,", " @DateTimeFormat(iso = TIME) String time) {}", + "", + " @SpringBootTest(webEnvironment = RANDOM_PORT)", + " final class Foo {}", "}") .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); } diff --git a/pom.xml b/pom.xml index 4b75abfddf3..2de1c00ef3c 100644 --- a/pom.xml +++ b/pom.xml @@ -281,7 +281,7 @@ io.projectreactor reactor-bom - 2020.0.11 + 2020.0.12 pom import @@ -367,10 +367,15 @@ org.springframework spring-framework-bom - 5.3.10 + 5.3.12 pom import + + org.springframework.boot + spring-boot-test + 2.5.6 + org.testng testng @@ -990,6 +995,7 @@ BSD-3-Clause + | BSD License 3 | 3-Clause BSD License | BSD 3-clause | Eclipse Distribution License (New BSD License)