|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 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.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.expression.spel;
|
18 | 18 |
|
19 |
| -import static org.junit.Assert.assertEquals; |
20 |
| -import static org.junit.Assert.assertFalse; |
21 |
| -import static org.junit.Assert.assertTrue; |
22 |
| -import static org.junit.Assert.fail; |
23 |
| - |
24 | 19 | import org.junit.Test;
|
| 20 | + |
25 | 21 | import org.springframework.expression.EvaluationContext;
|
26 | 22 | import org.springframework.expression.EvaluationException;
|
27 | 23 | import org.springframework.expression.Expression;
|
|
32 | 28 | import org.springframework.expression.spel.standard.SpelExpressionParser;
|
33 | 29 | import org.springframework.expression.spel.support.StandardEvaluationContext;
|
34 | 30 |
|
| 31 | +import static org.junit.Assert.*; |
| 32 | + |
35 | 33 | /**
|
36 | 34 | * @author Andy Clement
|
37 | 35 | * @author Juergen Hoeller
|
@@ -68,8 +66,8 @@ public boolean isTemplate() {
|
68 | 66 | }
|
69 | 67 | };
|
70 | 68 |
|
71 |
| - @Test |
72 | 69 |
|
| 70 | + @Test |
73 | 71 | public void testParsingSimpleTemplateExpression01() throws Exception {
|
74 | 72 | SpelExpressionParser parser = new SpelExpressionParser();
|
75 | 73 | Expression expr = parser.parseExpression("hello ${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
@@ -148,19 +146,22 @@ public void testCompositeStringExpression() throws Exception {
|
148 | 146 | try {
|
149 | 147 | ex.setValue(ctx, null);
|
150 | 148 | fail();
|
151 |
| - } catch (EvaluationException ee) { |
| 149 | + } |
| 150 | + catch (EvaluationException ee) { |
152 | 151 | // success
|
153 | 152 | }
|
154 | 153 | try {
|
155 | 154 | ex.setValue((Object)null, null);
|
156 | 155 | fail();
|
157 |
| - } catch (EvaluationException ee) { |
| 156 | + } |
| 157 | + catch (EvaluationException ee) { |
158 | 158 | // success
|
159 | 159 | }
|
160 | 160 | try {
|
161 | 161 | ex.setValue(ctx, null, null);
|
162 | 162 | fail();
|
163 |
| - } catch (EvaluationException ee) { |
| 163 | + } |
| 164 | + catch (EvaluationException ee) { |
164 | 165 | // success
|
165 | 166 | }
|
166 | 167 | }
|
@@ -192,15 +193,17 @@ public void testNestedExpressions() throws Exception {
|
192 | 193 | try {
|
193 | 194 | ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5] world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
194 | 195 | fail("Should have failed");
|
195 |
| - } catch (ParseException pe) { |
196 |
| - assertEquals("No ending suffix '}' for expression starting at character 41: ${listOfNumbersUpToTen.$[#this>5] world",pe.getMessage()); |
| 196 | + } |
| 197 | + catch (ParseException pe) { |
| 198 | + assertEquals("No ending suffix '}' for expression starting at character 41: ${listOfNumbersUpToTen.$[#this>5] world", pe.getMessage()); |
197 | 199 | }
|
198 | 200 |
|
199 | 201 | try {
|
200 | 202 | ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1==3]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
201 | 203 | fail("Should have failed");
|
202 |
| - } catch (ParseException pe) { |
203 |
| - assertEquals("Found closing '}' at position 74 but most recent opening is '[' at position 30",pe.getMessage()); |
| 204 | + } |
| 205 | + catch (ParseException pe) { |
| 206 | + assertEquals("Found closing '}' at position 74 but most recent opening is '[' at position 30", pe.getMessage()); |
204 | 207 | }
|
205 | 208 | }
|
206 | 209 |
|
@@ -234,21 +237,24 @@ public void testErrorCases() throws Exception {
|
234 | 237 | try {
|
235 | 238 | parser.parseExpression("hello ${'world'", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
236 | 239 | fail("Should have failed");
|
237 |
| - } catch (ParseException pe) { |
238 |
| - assertEquals("No ending suffix '}' for expression starting at character 6: ${'world'",pe.getMessage()); |
| 240 | + } |
| 241 | + catch (ParseException pe) { |
| 242 | + assertEquals("No ending suffix '}' for expression starting at character 6: ${'world'", pe.getMessage()); |
239 | 243 | assertEquals("hello ${'world'",pe.getExpressionString());
|
240 | 244 | }
|
241 | 245 | try {
|
242 | 246 | parser.parseExpression("hello ${'wibble'${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
243 | 247 | fail("Should have failed");
|
244 |
| - } catch (ParseException pe) { |
245 |
| - assertEquals("No ending suffix '}' for expression starting at character 6: ${'wibble'${'world'}",pe.getMessage()); |
| 248 | + } |
| 249 | + catch (ParseException pe) { |
| 250 | + assertEquals("No ending suffix '}' for expression starting at character 6: ${'wibble'${'world'}", pe.getMessage()); |
246 | 251 | }
|
247 | 252 | try {
|
248 | 253 | parser.parseExpression("hello ${} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
249 | 254 | fail("Should have failed");
|
250 |
| - } catch (ParseException pe) { |
251 |
| - assertEquals("No expression defined within delimiter '${}' at character 6",pe.getMessage()); |
| 255 | + } |
| 256 | + catch (ParseException pe) { |
| 257 | + assertEquals("No expression defined within delimiter '${}' at character 6", pe.getMessage()); |
252 | 258 | }
|
253 | 259 | }
|
254 | 260 |
|
|
0 commit comments