Fix flaky SpEL tests

This commit fixes SpEL related tests that failed if the test methods
were executed in a different order than in the Gradle build.

(cherry picked from commit 97e10a5948)
This commit is contained in:
Sam Brannen
2026-04-06 16:51:50 +02:00
parent 659271cf61
commit b2069e4c37
3 changed files with 19 additions and 1 deletions
@@ -19,6 +19,7 @@ package org.springframework.expression.spel;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.expression.ConstructorResolver;
@@ -41,6 +42,11 @@ import static org.assertj.core.api.Assertions.assertThatException;
*/
class ConstructorInvocationTests extends AbstractExpressionTests {
@BeforeEach
void resetCounter() {
Tester.counter = 0;
}
@Test
void constructorWithArgument() {
evaluate("new String('hello world')", "hello world", String.class);
@@ -2966,6 +2966,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
assertThat((Boolean) expression.getValue(tvar)).isFalse();
TestClass7 tc7 = new TestClass7();
TestClass7.reset();
expression = parse("property == 'UK'");
assertThat((Boolean) expression.getValue(tc7)).isTrue();
TestClass7.property = null;
@@ -37,6 +37,7 @@ import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
@@ -85,6 +86,12 @@ class SpelReproTests extends AbstractExpressionTests {
private static final ParserContext DOLLARSQUARE_TEMPLATE_PARSER_CONTEXT = new TemplateParserContext("$[", "]");
@BeforeEach
void resetGoo() {
Goo.reset();
}
@Test
void NPE_SPR5661() {
evaluate("joinThreeStrings('a',null,'c')", "anullc", String.class);
@@ -1880,7 +1887,11 @@ class SpelReproTests extends AbstractExpressionTests {
static class Goo {
public static Goo instance = new Goo();
public static Goo instance;
static void reset() {
instance = new Goo();
}
public String bar = "key";