diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml
index 8d71bb4b6c..56021df1d5 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 b0efa3dedb..5a5eb98208 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 ee6520dc64..c17a4d4350 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:",
+ " Object e1 = WebEnvironment.RANDOM_PORT;",
+ " Object e2 = 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 Test {}",
"}")
.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 Test {}",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
}
diff --git a/pom.xml b/pom.xml
index 1d50626bf7..425bb807dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -371,6 +371,11 @@
pom
import
+
+ org.springframework.boot
+ spring-boot-test
+ 2.5.6
+
org.testng
testng