From a25d67770e671c684caa0395cd88e99597a0fad7 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 26 Mar 2014 21:00:33 +0100 Subject: [PATCH] Added expression test case for constant on Map Issue: SPR-11609 --- .../context/expression/MapAccessor.java | 4 +- .../expression/spel/SpelReproTests.java | 62 +++++++++++-------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java b/spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java index 155fefbbc1b..a580cf39849 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java +++ b/spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java @@ -57,8 +57,8 @@ public class MapAccessor implements PropertyAccessor { map.put(name, newValue); } - public Class[] getSpecificTargetClasses() { - return new Class[] {Map.class}; + public Class[] getSpecificTargetClasses() { + return new Class[] {Map.class}; } diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java index f70d124a840..6b4bb2f449c 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java @@ -1769,10 +1769,10 @@ public class SpelReproTests extends ExpressionTestCase { public void SPR10486() throws Exception { SpelExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext context = new StandardEvaluationContext(); - SPR10486 rootObject = new SPR10486(); + Spr10486 rootObject = new Spr10486(); Expression classNameExpression = parser.parseExpression("class.name"); Expression nameExpression = parser.parseExpression("name"); - assertThat(classNameExpression.getValue(context, rootObject), equalTo((Object) SPR10486.class.getName())); + assertThat(classNameExpression.getValue(context, rootObject), equalTo((Object) Spr10486.class.getName())); assertThat(nameExpression.getValue(context, rootObject), equalTo((Object) "name")); } @@ -1780,7 +1780,7 @@ public class SpelReproTests extends ExpressionTestCase { public void SPR11142() throws Exception { SpelExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext context = new StandardEvaluationContext(); - SPR11142 rootObject = new SPR11142(); + Spr11142 rootObject = new Spr11142(); Expression expression = parser.parseExpression("something"); thrown.expect(SpelEvaluationException.class); thrown.expectMessage("'something' cannot be found"); @@ -1819,26 +1819,6 @@ public class SpelReproTests extends ExpressionTestCase { assertEquals(1, expr.getValue(context)); } - - static class Spr11445Class implements BeanResolver { - - private final AtomicInteger counter = new AtomicInteger(); - - public int echo(int invocation) { - return invocation; - } - - public int parameter() { - return counter.incrementAndGet(); - } - - @Override - public Object resolve(EvaluationContext context, String beanName) throws AccessException { - return beanName.equals("bean") ? this : null; - } - } - - @Test public void SPR11494() { Expression exp = new SpelExpressionParser().parseExpression("T(java.util.Arrays).asList('a','b')"); @@ -1846,6 +1826,13 @@ public class SpelReproTests extends ExpressionTestCase { assertThat(list.size(), is(2)); } + @Test + public void SPR11609() { + Expression exp = new SpelExpressionParser().parseExpression( + "T(org.springframework.expression.spel.SpelReproTests$MapWithConstant).X"); + assertEquals(1, exp.getValue()); + } + private static enum ABC { A, B, C } @@ -1921,7 +1908,7 @@ public class SpelReproTests extends ExpressionTestCase { } - public static class SPR10486 { + public static class Spr10486 { private String name = "name"; @@ -1935,7 +1922,7 @@ public class SpelReproTests extends ExpressionTestCase { } - static class SPR11142 { + static class Spr11142 { public String isSomething() { return ""; @@ -1965,4 +1952,29 @@ public class SpelReproTests extends ExpressionTestCase { } } + + static class Spr11445Class implements BeanResolver { + + private final AtomicInteger counter = new AtomicInteger(); + + public int echo(int invocation) { + return invocation; + } + + public int parameter() { + return counter.incrementAndGet(); + } + + @Override + public Object resolve(EvaluationContext context, String beanName) throws AccessException { + return beanName.equals("bean") ? this : null; + } + } + + + public static class MapWithConstant extends HashMap { + + public static final int X = 1; + } + }