Skip to content

Commit 9aefa03

Browse files
committed
Polishing
1 parent f532607 commit 9aefa03

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public String tryToInvokeWithNull3(Integer value, String... strings) {
175175
return sb.toString();
176176
}
177177

178+
@Override
178179
public String toString() {
179180
return "instance";
180181
}
@@ -559,24 +560,24 @@ static class Holder {
559560
// ---
560561

561562
private void checkTemplateParsing(String expression, String expectedValue) throws Exception {
562-
checkTemplateParsing(expression,TemplateExpressionParsingTests.DEFAULT_TEMPLATE_PARSER_CONTEXT, expectedValue);
563+
checkTemplateParsing(expression, TemplateExpressionParsingTests.DEFAULT_TEMPLATE_PARSER_CONTEXT, expectedValue);
563564
}
564565

565566
private void checkTemplateParsing(String expression, ParserContext context, String expectedValue) throws Exception {
566567
SpelExpressionParser parser = new SpelExpressionParser();
567568
Expression expr = parser.parseExpression(expression,context);
568-
assertEquals(expectedValue,expr.getValue(TestScenarioCreator.getTestEvaluationContext()));
569+
assertEquals(expectedValue, expr.getValue(TestScenarioCreator.getTestEvaluationContext()));
569570
}
570571

571-
private void checkTemplateParsingError(String expression,String expectedMessage) throws Exception {
572-
checkTemplateParsingError(expression, TemplateExpressionParsingTests.DEFAULT_TEMPLATE_PARSER_CONTEXT,expectedMessage);
572+
private void checkTemplateParsingError(String expression, String expectedMessage) throws Exception {
573+
checkTemplateParsingError(expression, TemplateExpressionParsingTests.DEFAULT_TEMPLATE_PARSER_CONTEXT, expectedMessage);
573574
}
574575

575-
private void checkTemplateParsingError(String expression,ParserContext context, String expectedMessage) throws Exception {
576+
private void checkTemplateParsingError(String expression, ParserContext context, String expectedMessage) throws Exception {
576577
SpelExpressionParser parser = new SpelExpressionParser();
577578
try {
578-
parser.parseExpression(expression,context);
579-
fail("Should have failed");
579+
parser.parseExpression(expression, context);
580+
fail("Should have failed with message: " + expectedMessage);
580581
}
581582
catch (Exception ex) {
582583
if (!ex.getMessage().equals(expectedMessage)) {
@@ -587,17 +588,14 @@ private void checkTemplateParsingError(String expression,ParserContext context,
587588
}
588589

589590
private static final ParserContext DOLLARSQUARE_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
590-
591591
@Override
592592
public String getExpressionPrefix() {
593593
return "$[";
594594
}
595-
596595
@Override
597596
public String getExpressionSuffix() {
598597
return "]";
599598
}
600-
601599
@Override
602600
public boolean isTemplate() {
603601
return true;
@@ -826,6 +824,7 @@ private D(String s) {
826824
a=s;
827825
}
828826

827+
@Override
829828
public String toString() {
830829
return "D("+a+")";
831830
}

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -16,12 +16,8 @@
1616

1717
package org.springframework.expression.spel;
1818

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-
2419
import org.junit.Test;
20+
2521
import org.springframework.expression.EvaluationContext;
2622
import org.springframework.expression.EvaluationException;
2723
import org.springframework.expression.Expression;
@@ -32,6 +28,8 @@
3228
import org.springframework.expression.spel.standard.SpelExpressionParser;
3329
import org.springframework.expression.spel.support.StandardEvaluationContext;
3430

31+
import static org.junit.Assert.*;
32+
3533
/**
3634
* @author Andy Clement
3735
* @author Juergen Hoeller
@@ -68,8 +66,8 @@ public boolean isTemplate() {
6866
}
6967
};
7068

71-
@Test
7269

70+
@Test
7371
public void testParsingSimpleTemplateExpression01() throws Exception {
7472
SpelExpressionParser parser = new SpelExpressionParser();
7573
Expression expr = parser.parseExpression("hello ${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
@@ -148,19 +146,22 @@ public void testCompositeStringExpression() throws Exception {
148146
try {
149147
ex.setValue(ctx, null);
150148
fail();
151-
} catch (EvaluationException ee) {
149+
}
150+
catch (EvaluationException ee) {
152151
// success
153152
}
154153
try {
155154
ex.setValue((Object)null, null);
156155
fail();
157-
} catch (EvaluationException ee) {
156+
}
157+
catch (EvaluationException ee) {
158158
// success
159159
}
160160
try {
161161
ex.setValue(ctx, null, null);
162162
fail();
163-
} catch (EvaluationException ee) {
163+
}
164+
catch (EvaluationException ee) {
164165
// success
165166
}
166167
}
@@ -192,15 +193,17 @@ public void testNestedExpressions() throws Exception {
192193
try {
193194
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5] world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
194195
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());
197199
}
198200

199201
try {
200202
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1==3]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
201203
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());
204207
}
205208
}
206209

@@ -234,21 +237,24 @@ public void testErrorCases() throws Exception {
234237
try {
235238
parser.parseExpression("hello ${'world'", DEFAULT_TEMPLATE_PARSER_CONTEXT);
236239
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());
239243
assertEquals("hello ${'world'",pe.getExpressionString());
240244
}
241245
try {
242246
parser.parseExpression("hello ${'wibble'${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
243247
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());
246251
}
247252
try {
248253
parser.parseExpression("hello ${} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
249254
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());
252258
}
253259
}
254260

0 commit comments

Comments
 (0)