Skip to content

Commit 9d47a2b

Browse files
committed
Explicit test for default useDistance mode
Issue: SPR-12808
1 parent 69b3e00 commit 9d47a2b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,21 @@ public void SPR12803() throws Exception {
19041904
assertTrue(expression.getValue(sec) instanceof ArrayList);
19051905
}
19061906

1907+
@Test
1908+
public void SPR12808() throws Exception {
1909+
SpelExpressionParser parser = new SpelExpressionParser();
1910+
Expression expression = parser.parseExpression("T(org.springframework.expression.spel.SpelReproTests.DistanceEnforcer).from(#no)");
1911+
StandardEvaluationContext sec = new StandardEvaluationContext();
1912+
sec.setVariable("no", new Integer(1));
1913+
assertTrue(expression.getValue(sec).toString().startsWith("Integer"));
1914+
sec = new StandardEvaluationContext();
1915+
sec.setVariable("no", new Float(1.0));
1916+
assertTrue(expression.getValue(sec).toString().startsWith("Number"));
1917+
sec = new StandardEvaluationContext();
1918+
sec.setVariable("no", "1.0");
1919+
assertTrue(expression.getValue(sec).toString().startsWith("Object"));
1920+
}
1921+
19071922

19081923
private static enum ABC { A, B, C }
19091924

@@ -2201,4 +2216,20 @@ public static <T> List<T> newArrayList(Object... elements) {
22012216
}
22022217
}
22032218

2219+
2220+
public static class DistanceEnforcer {
2221+
2222+
public static String from(Number no) {
2223+
return "Number:" + no.toString();
2224+
}
2225+
2226+
public static String from(Integer no) {
2227+
return "Integer:" + no.toString();
2228+
}
2229+
2230+
public static String from(Object no) {
2231+
return "Object:" + no.toString();
2232+
}
2233+
}
2234+
22042235
}

0 commit comments

Comments
 (0)