Skip to content

Commit 97e10a5

Browse files
committed
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.
1 parent bfbfe4a commit 97e10a5

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

spring-expression/src/test/java/org/springframework/expression/spel/ConstructorInvocationTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.junit.jupiter.api.BeforeEach;
2223
import org.junit.jupiter.api.Test;
2324

2425
import org.springframework.expression.ConstructorResolver;
@@ -41,6 +42,11 @@
4142
*/
4243
class ConstructorInvocationTests extends AbstractExpressionTests {
4344

45+
@BeforeEach
46+
void resetCounter() {
47+
Tester.counter = 0;
48+
}
49+
4450
@Test
4551
void constructorWithArgument() {
4652
evaluate("new String('hello world')", "hello world", String.class);

spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,6 +2967,7 @@ void opEq() {
29672967
assertThat((Boolean) expression.getValue(tvar)).isFalse();
29682968

29692969
TestClass7 tc7 = new TestClass7();
2970+
TestClass7.reset();
29702971
expression = parse("property == 'UK'");
29712972
assertThat((Boolean) expression.getValue(tc7)).isTrue();
29722973
TestClass7.property = null;

spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import org.assertj.core.api.InstanceOfAssertFactories;
4040
import org.jspecify.annotations.Nullable;
41+
import org.junit.jupiter.api.BeforeEach;
4142
import org.junit.jupiter.api.Test;
4243

4344
import org.springframework.core.MethodParameter;
@@ -85,6 +86,12 @@ class SpelReproTests extends AbstractExpressionTests {
8586
private static final ParserContext DOLLARSQUARE_TEMPLATE_PARSER_CONTEXT = new TemplateParserContext("$[", "]");
8687

8788

89+
@BeforeEach
90+
void resetGoo() {
91+
Goo.reset();
92+
}
93+
94+
8895
@Test
8996
void NPE_SPR5661() {
9097
evaluate("joinThreeStrings('a',null,'c')", "anullc", String.class);
@@ -1879,7 +1886,11 @@ public void setPayload(String payload) {
18791886

18801887
static class Goo {
18811888

1882-
public static Goo instance = new Goo();
1889+
public static Goo instance;
1890+
1891+
static void reset() {
1892+
instance = new Goo();
1893+
}
18831894

18841895
public String bar = "key";
18851896

0 commit comments

Comments
 (0)