From c68021760ded9b7d6ab46e13f92e64d6347c5b3a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 5 Jul 2011 22:06:14 +0000 Subject: [PATCH] fixed TypeDescriptor rendering (SPR-8508) --- .../expression/spel/ast/FormatHelper.java | 11 ++--- .../spel/ast/FormatHelperTests.java | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 org.springframework.expression/src/test/java/org/springframework/expression/spel/ast/FormatHelperTests.java diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java index 377cb5e415c..f0af0bbbb1d 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,9 @@ public class FormatHelper { } TypeDescriptor typeDescriptor = argumentTypes.get(i); if (typeDescriptor != null) { - sb.append(formatClassNameForMessage(typeDescriptor.getClass())); - } else { + sb.append(formatClassNameForMessage(typeDescriptor.getType())); + } + else { sb.append(formatClassNameForMessage(null)); } } @@ -53,8 +54,8 @@ public class FormatHelper { } /** - * Produce a nice string for a given class object. For example a string array will have the formatted name - * "java.lang.String[]". + * Produce a nice string for a given class object. + * For example, a string array will have the formatted name "java.lang.String[]". * @param clazz The class whose name is to be formatted * @return a formatted string suitable for message inclusion */ diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ast/FormatHelperTests.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ast/FormatHelperTests.java new file mode 100644 index 00000000000..abd8ed775e1 --- /dev/null +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ast/FormatHelperTests.java @@ -0,0 +1,44 @@ +/* + * Copyright 2002-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.expression.spel.ast; + +import java.util.Arrays; + +import org.junit.Test; + +import org.springframework.core.convert.TypeDescriptor; + +import static org.junit.Assert.*; + +/** + * @author Andy Wilkinson + */ +public class FormatHelperTests { + + @Test + public void formatMethodWithSingleArgumentForMessage() { + String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string"))); + assertEquals("foo(java.lang.String)", message); + } + + @Test + public void formatMethodWithMultipleArgumentsForMessage() { + String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string"), TypeDescriptor.forObject(Integer.valueOf(5)))); + assertEquals("foo(java.lang.String,java.lang.Integer)", message); + } + +}