From 9d47a2b87e234ce25d48b7af278e59cef0329a45 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 13 Mar 2015 18:16:58 +0100 Subject: [PATCH] Explicit test for default useDistance mode Issue: SPR-12808 --- .../expression/spel/SpelReproTests.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 3fc0db8dc10..f025594421f 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 @@ -1904,6 +1904,21 @@ public class SpelReproTests extends AbstractExpressionTests { assertTrue(expression.getValue(sec) instanceof ArrayList); } + @Test + public void SPR12808() throws Exception { + SpelExpressionParser parser = new SpelExpressionParser(); + Expression expression = parser.parseExpression("T(org.springframework.expression.spel.SpelReproTests.DistanceEnforcer).from(#no)"); + StandardEvaluationContext sec = new StandardEvaluationContext(); + sec.setVariable("no", new Integer(1)); + assertTrue(expression.getValue(sec).toString().startsWith("Integer")); + sec = new StandardEvaluationContext(); + sec.setVariable("no", new Float(1.0)); + assertTrue(expression.getValue(sec).toString().startsWith("Number")); + sec = new StandardEvaluationContext(); + sec.setVariable("no", "1.0"); + assertTrue(expression.getValue(sec).toString().startsWith("Object")); + } + private static enum ABC { A, B, C } @@ -2201,4 +2216,20 @@ public class SpelReproTests extends AbstractExpressionTests { } } + + public static class DistanceEnforcer { + + public static String from(Number no) { + return "Number:" + no.toString(); + } + + public static String from(Integer no) { + return "Integer:" + no.toString(); + } + + public static String from(Object no) { + return "Object:" + no.toString(); + } + } + }