Browse Source

added testStringArrayToResourceArray

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3591 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
e8bef9d800
  1. 24
      org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java

24
org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java

@ -31,6 +31,8 @@ import org.springframework.core.convert.ConversionFailedException; @@ -31,6 +31,8 @@ import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.io.Resource;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
@ -217,6 +219,16 @@ public class GenericConversionServiceTests { @@ -217,6 +219,16 @@ public class GenericConversionServiceTests {
assertEquals("RESULT", converted[0]);
}
@Test
public void testStringArrayToResourceArray() {
GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
conversionService.addConverter(new MyStringArrayToResourceArrayConverter());
Resource[] converted = conversionService.convert(new String[] {"x1", "z3"}, Resource[].class);
assertEquals(2, converted.length);
assertEquals("1", converted[0].getDescription());
assertEquals("3", converted[1].getDescription());
}
@Test
public void testStringArrayToIntegerArray() {
GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
@ -393,6 +405,18 @@ public class GenericConversionServiceTests { @@ -393,6 +405,18 @@ public class GenericConversionServiceTests {
}
private static class MyStringArrayToResourceArrayConverter implements Converter<String[], Resource[]> {
public Resource[] convert(String[] source) {
Resource[] result = new Resource[source.length];
for (int i = 0; i < source.length; i++) {
result[i] = new DescriptiveResource(source[i].substring(1));
}
return result;
}
}
private static class MyStringArrayToIntegerArrayConverter implements Converter<String[], Integer[]> {
public Integer[] convert(String[] source) {

Loading…
Cancel
Save