Skip to content

Commit 5afd94f

Browse files
committed
Polish SpelParserTests and TemplateExpressionParsingTests
1 parent ec5f764 commit 5afd94f

File tree

2 files changed

+104
-124
lines changed

2 files changed

+104
-124
lines changed

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,10 +34,11 @@
3434
/**
3535
* @author Andy Clement
3636
* @author Juergen Hoeller
37+
* @author Sam Brannen
3738
*/
38-
public class TemplateExpressionParsingTests extends AbstractExpressionTests {
39+
class TemplateExpressionParsingTests extends AbstractExpressionTests {
3940

40-
public static final ParserContext DEFAULT_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
41+
static final ParserContext DEFAULT_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
4142
@Override
4243
public String getExpressionPrefix() {
4344
return "${";
@@ -52,7 +53,7 @@ public boolean isTemplate() {
5253
}
5354
};
5455

55-
public static final ParserContext HASH_DELIMITED_PARSER_CONTEXT = new ParserContext() {
56+
static final ParserContext HASH_DELIMITED_PARSER_CONTEXT = new ParserContext() {
5657
@Override
5758
public String getExpressionPrefix() {
5859
return "#{";
@@ -68,34 +69,33 @@ public boolean isTemplate() {
6869
};
6970

7071

72+
private final SpelExpressionParser parser = new SpelExpressionParser();
73+
74+
7175
@Test
72-
public void testParsingSimpleTemplateExpression01() throws Exception {
73-
SpelExpressionParser parser = new SpelExpressionParser();
76+
void parsingSimpleTemplateExpression01() {
7477
Expression expr = parser.parseExpression("hello ${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
7578
Object o = expr.getValue();
7679
assertThat(o.toString()).isEqualTo("hello world");
7780
}
7881

7982
@Test
80-
public void testParsingSimpleTemplateExpression02() throws Exception {
81-
SpelExpressionParser parser = new SpelExpressionParser();
83+
void parsingSimpleTemplateExpression02() {
8284
Expression expr = parser.parseExpression("hello ${'to'} you", DEFAULT_TEMPLATE_PARSER_CONTEXT);
8385
Object o = expr.getValue();
8486
assertThat(o.toString()).isEqualTo("hello to you");
8587
}
8688

8789
@Test
88-
public void testParsingSimpleTemplateExpression03() throws Exception {
89-
SpelExpressionParser parser = new SpelExpressionParser();
90+
void parsingSimpleTemplateExpression03() {
9091
Expression expr = parser.parseExpression("The quick ${'brown'} fox jumped over the ${'lazy'} dog",
9192
DEFAULT_TEMPLATE_PARSER_CONTEXT);
9293
Object o = expr.getValue();
9394
assertThat(o.toString()).isEqualTo("The quick brown fox jumped over the lazy dog");
9495
}
9596

9697
@Test
97-
public void testParsingSimpleTemplateExpression04() throws Exception {
98-
SpelExpressionParser parser = new SpelExpressionParser();
98+
void parsingSimpleTemplateExpression04() {
9999
Expression expr = parser.parseExpression("${'hello'} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
100100
Object o = expr.getValue();
101101
assertThat(o.toString()).isEqualTo("hello world");
@@ -114,8 +114,7 @@ public void testParsingSimpleTemplateExpression04() throws Exception {
114114
}
115115

116116
@Test
117-
public void testCompositeStringExpression() throws Exception {
118-
SpelExpressionParser parser = new SpelExpressionParser();
117+
void compositeStringExpression() {
119118
Expression ex = parser.parseExpression("hello ${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
120119
assertThat(ex.getValue()).isInstanceOf(String.class).isEqualTo("hello world");
121120
assertThat(ex.getValue(String.class)).isInstanceOf(String.class).isEqualTo("hello world");
@@ -154,8 +153,7 @@ public void testCompositeStringExpression() throws Exception {
154153
static class Rooty {}
155154

156155
@Test
157-
public void testNestedExpressions() throws Exception {
158-
SpelExpressionParser parser = new SpelExpressionParser();
156+
void nestedExpressions() {
159157
// treat the nested ${..} as a part of the expression
160158
Expression ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
161159
String s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
@@ -185,8 +183,7 @@ public void testNestedExpressions() throws Exception {
185183
}
186184

187185
@Test
188-
189-
public void testClashingWithSuffixes() throws Exception {
186+
void clashingWithSuffixes() {
190187
// Just wanting to use the prefix or suffix within the template:
191188
Expression ex = parser.parseExpression("hello ${3+4} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
192189
String s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
@@ -202,13 +199,13 @@ public void testClashingWithSuffixes() throws Exception {
202199
}
203200

204201
@Test
205-
public void testParsingNormalExpressionThroughTemplateParser() throws Exception {
202+
void parsingNormalExpressionThroughTemplateParser() {
206203
Expression expr = parser.parseExpression("1+2+3");
207204
assertThat(expr.getValue()).isEqualTo(6);
208205
}
209206

210207
@Test
211-
public void testErrorCases() throws Exception {
208+
void errorCases() {
212209
assertThatExceptionOfType(ParseException.class).isThrownBy(() ->
213210
parser.parseExpression("hello ${'world'", DEFAULT_TEMPLATE_PARSER_CONTEXT))
214211
.satisfies(pex -> {
@@ -224,7 +221,7 @@ public void testErrorCases() throws Exception {
224221
}
225222

226223
@Test
227-
public void testTemplateParserContext() {
224+
void testTemplateParserContext() {
228225
TemplateParserContext tpc = new TemplateParserContext("abc","def");
229226
assertThat(tpc.getExpressionPrefix()).isEqualTo("abc");
230227
assertThat(tpc.getExpressionSuffix()).isEqualTo("def");

0 commit comments

Comments
 (0)