From 7aae97bcd469105ac2f2aa76ce93f38df455e3b9 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 25 Sep 2023 16:48:58 +0200 Subject: [PATCH] Revise NO_VIOLATIONS_DETECTED in SpringExtension to clarify intent See gh-31305 See gh-30962 See gh-30456 --- .../test/context/junit/jupiter/SpringExtension.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java index aadf76c43e..74477bfe13 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java @@ -24,7 +24,6 @@ import java.lang.reflect.Modifier; import java.lang.reflect.Parameter; import java.util.Arrays; import java.util.List; -import java.util.Objects; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -99,7 +98,12 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes private static final Namespace AUTOWIRED_VALIDATION_NAMESPACE = Namespace.create(SpringExtension.class.getName() + "#autowired.validation"); - private static final String NO_VIOLATIONS_DETECTED = "NO VIOLATIONS DETECTED"; + /** + * Marker string constant to represent that no violations were detected. + *

The value is an empty string which allows this class to perform quick + * {@code isEmpty()} checks instead of performing unnecessary string comparisons. + */ + private static final String NO_VIOLATIONS_DETECTED = ""; /** * {@link Namespace} in which {@code @RecordApplicationEvents} validation error messages @@ -180,7 +184,7 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes testClass.getName(), Arrays.toString(methodsWithErrors))); }, String.class); - if (!Objects.equals(errorMessage, NO_VIOLATIONS_DETECTED)) { + if (!errorMessage.isEmpty()) { throw new IllegalStateException(errorMessage); } } @@ -219,7 +223,7 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes published by other tests since the application context may be shared."""; }, String.class); - if (!Objects.equals(errorMessage, NO_VIOLATIONS_DETECTED)) { + if (!errorMessage.isEmpty()) { throw new IllegalStateException(errorMessage); } }