Skip to content

Commit

Permalink
added testStringArrayToResourceArray
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Aug 15, 2010
1 parent d1afb29 commit 5c3cf5f
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
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;

Expand Down Expand Up @@ -217,6 +219,16 @@ public void testObjectArrayToStringArray() {
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();
Expand Down Expand Up @@ -393,6 +405,18 @@ public String convert(MyBaseInterface source) {
}


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) {
Expand Down

0 comments on commit 5c3cf5f

Please sign in to comment.