1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
34
34
/**
35
35
* @author Andy Clement
36
36
* @author Juergen Hoeller
37
+ * @author Sam Brannen
37
38
*/
38
- public class TemplateExpressionParsingTests extends AbstractExpressionTests {
39
+ class TemplateExpressionParsingTests extends AbstractExpressionTests {
39
40
40
- public static final ParserContext DEFAULT_TEMPLATE_PARSER_CONTEXT = new ParserContext () {
41
+ static final ParserContext DEFAULT_TEMPLATE_PARSER_CONTEXT = new ParserContext () {
41
42
@ Override
42
43
public String getExpressionPrefix () {
43
44
return "${" ;
@@ -52,7 +53,7 @@ public boolean isTemplate() {
52
53
}
53
54
};
54
55
55
- public static final ParserContext HASH_DELIMITED_PARSER_CONTEXT = new ParserContext () {
56
+ static final ParserContext HASH_DELIMITED_PARSER_CONTEXT = new ParserContext () {
56
57
@ Override
57
58
public String getExpressionPrefix () {
58
59
return "#{" ;
@@ -68,34 +69,33 @@ public boolean isTemplate() {
68
69
};
69
70
70
71
72
+ private final SpelExpressionParser parser = new SpelExpressionParser ();
73
+
74
+
71
75
@ Test
72
- public void testParsingSimpleTemplateExpression01 () throws Exception {
73
- SpelExpressionParser parser = new SpelExpressionParser ();
76
+ void parsingSimpleTemplateExpression01 () {
74
77
Expression expr = parser .parseExpression ("hello ${'world'}" , DEFAULT_TEMPLATE_PARSER_CONTEXT );
75
78
Object o = expr .getValue ();
76
79
assertThat (o .toString ()).isEqualTo ("hello world" );
77
80
}
78
81
79
82
@ Test
80
- public void testParsingSimpleTemplateExpression02 () throws Exception {
81
- SpelExpressionParser parser = new SpelExpressionParser ();
83
+ void parsingSimpleTemplateExpression02 () {
82
84
Expression expr = parser .parseExpression ("hello ${'to'} you" , DEFAULT_TEMPLATE_PARSER_CONTEXT );
83
85
Object o = expr .getValue ();
84
86
assertThat (o .toString ()).isEqualTo ("hello to you" );
85
87
}
86
88
87
89
@ Test
88
- public void testParsingSimpleTemplateExpression03 () throws Exception {
89
- SpelExpressionParser parser = new SpelExpressionParser ();
90
+ void parsingSimpleTemplateExpression03 () {
90
91
Expression expr = parser .parseExpression ("The quick ${'brown'} fox jumped over the ${'lazy'} dog" ,
91
92
DEFAULT_TEMPLATE_PARSER_CONTEXT );
92
93
Object o = expr .getValue ();
93
94
assertThat (o .toString ()).isEqualTo ("The quick brown fox jumped over the lazy dog" );
94
95
}
95
96
96
97
@ Test
97
- public void testParsingSimpleTemplateExpression04 () throws Exception {
98
- SpelExpressionParser parser = new SpelExpressionParser ();
98
+ void parsingSimpleTemplateExpression04 () {
99
99
Expression expr = parser .parseExpression ("${'hello'} world" , DEFAULT_TEMPLATE_PARSER_CONTEXT );
100
100
Object o = expr .getValue ();
101
101
assertThat (o .toString ()).isEqualTo ("hello world" );
@@ -114,8 +114,7 @@ public void testParsingSimpleTemplateExpression04() throws Exception {
114
114
}
115
115
116
116
@ Test
117
- public void testCompositeStringExpression () throws Exception {
118
- SpelExpressionParser parser = new SpelExpressionParser ();
117
+ void compositeStringExpression () {
119
118
Expression ex = parser .parseExpression ("hello ${'world'}" , DEFAULT_TEMPLATE_PARSER_CONTEXT );
120
119
assertThat (ex .getValue ()).isInstanceOf (String .class ).isEqualTo ("hello world" );
121
120
assertThat (ex .getValue (String .class )).isInstanceOf (String .class ).isEqualTo ("hello world" );
@@ -154,8 +153,7 @@ public void testCompositeStringExpression() throws Exception {
154
153
static class Rooty {}
155
154
156
155
@ Test
157
- public void testNestedExpressions () throws Exception {
158
- SpelExpressionParser parser = new SpelExpressionParser ();
156
+ void nestedExpressions () {
159
157
// treat the nested ${..} as a part of the expression
160
158
Expression ex = parser .parseExpression ("hello ${listOfNumbersUpToTen.$[#this<5]} world" ,DEFAULT_TEMPLATE_PARSER_CONTEXT );
161
159
String s = ex .getValue (TestScenarioCreator .getTestEvaluationContext (),String .class );
@@ -185,8 +183,7 @@ public void testNestedExpressions() throws Exception {
185
183
}
186
184
187
185
@ Test
188
-
189
- public void testClashingWithSuffixes () throws Exception {
186
+ void clashingWithSuffixes () {
190
187
// Just wanting to use the prefix or suffix within the template:
191
188
Expression ex = parser .parseExpression ("hello ${3+4} world" ,DEFAULT_TEMPLATE_PARSER_CONTEXT );
192
189
String s = ex .getValue (TestScenarioCreator .getTestEvaluationContext (),String .class );
@@ -202,13 +199,13 @@ public void testClashingWithSuffixes() throws Exception {
202
199
}
203
200
204
201
@ Test
205
- public void testParsingNormalExpressionThroughTemplateParser () throws Exception {
202
+ void parsingNormalExpressionThroughTemplateParser () {
206
203
Expression expr = parser .parseExpression ("1+2+3" );
207
204
assertThat (expr .getValue ()).isEqualTo (6 );
208
205
}
209
206
210
207
@ Test
211
- public void testErrorCases () throws Exception {
208
+ void errorCases () {
212
209
assertThatExceptionOfType (ParseException .class ).isThrownBy (() ->
213
210
parser .parseExpression ("hello ${'world'" , DEFAULT_TEMPLATE_PARSER_CONTEXT ))
214
211
.satisfies (pex -> {
@@ -224,7 +221,7 @@ public void testErrorCases() throws Exception {
224
221
}
225
222
226
223
@ Test
227
- public void testTemplateParserContext () {
224
+ void testTemplateParserContext () {
228
225
TemplateParserContext tpc = new TemplateParserContext ("abc" ,"def" );
229
226
assertThat (tpc .getExpressionPrefix ()).isEqualTo ("abc" );
230
227
assertThat (tpc .getExpressionSuffix ()).isEqualTo ("def" );
0 commit comments