fixed TypeDescriptor rendering (SPR-8508)

This commit is contained in:
Juergen Hoeller 2011-07-05 22:06:14 +00:00
parent 352f053a71
commit c68021760d
2 changed files with 50 additions and 5 deletions

View File

@ -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
*/

View File

@ -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);
}
}