Skip to content

Commit 5c3cf5f

Browse files
committed
added testStringArrayToResourceArray
1 parent d1afb29 commit 5c3cf5f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.springframework.core.convert.ConverterNotFoundException;
3232
import org.springframework.core.convert.TypeDescriptor;
3333
import org.springframework.core.convert.converter.Converter;
34+
import org.springframework.core.io.Resource;
35+
import org.springframework.core.io.DescriptiveResource;
3436
import org.springframework.util.StopWatch;
3537
import org.springframework.util.StringUtils;
3638

@@ -217,6 +219,16 @@ public void testObjectArrayToStringArray() {
217219
assertEquals("RESULT", converted[0]);
218220
}
219221

222+
@Test
223+
public void testStringArrayToResourceArray() {
224+
GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
225+
conversionService.addConverter(new MyStringArrayToResourceArrayConverter());
226+
Resource[] converted = conversionService.convert(new String[] {"x1", "z3"}, Resource[].class);
227+
assertEquals(2, converted.length);
228+
assertEquals("1", converted[0].getDescription());
229+
assertEquals("3", converted[1].getDescription());
230+
}
231+
220232
@Test
221233
public void testStringArrayToIntegerArray() {
222234
GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
@@ -393,6 +405,18 @@ public String convert(MyBaseInterface source) {
393405
}
394406

395407

408+
private static class MyStringArrayToResourceArrayConverter implements Converter<String[], Resource[]> {
409+
410+
public Resource[] convert(String[] source) {
411+
Resource[] result = new Resource[source.length];
412+
for (int i = 0; i < source.length; i++) {
413+
result[i] = new DescriptiveResource(source[i].substring(1));
414+
}
415+
return result;
416+
}
417+
}
418+
419+
396420
private static class MyStringArrayToIntegerArrayConverter implements Converter<String[], Integer[]> {
397421

398422
public Integer[] convert(String[] source) {

0 commit comments

Comments
 (0)