RESOLVED - issue BATCH-1269: Add FieldSet support to PassThroughFieldExtractor

http://jira.springframework.org/browse/BATCH-1269
This commit is contained in:
dsyer
2009-06-03 14:52:20 +00:00
parent 751246a589
commit 88dfdba97e
2 changed files with 15 additions and 4 deletions

View File

@@ -58,6 +58,10 @@ public class PassThroughFieldExtractor<T> implements FieldExtractor<T> {
}
return args;
}
if (item instanceof FieldSet) {
return ((FieldSet) item).getValues();
}
return new Object[] { item };

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.batch.item.file.transform;
import static junit.framework.Assert.*;
import static junit.framework.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
@@ -29,21 +29,28 @@ import org.junit.Test;
public class PassThroughFieldExtractorTests {
@Test
public void testExtract_string() {
public void testExtractString() {
PassThroughFieldExtractor<String> extractor = new PassThroughFieldExtractor<String>();
Object[] result = extractor.extract("abc");
assertTrue(Arrays.equals(new Object[] { "abc" }, result));
}
@Test
public void testExtract_array() {
public void testExtractArray() {
PassThroughFieldExtractor<String[]> extractor = new PassThroughFieldExtractor<String[]>();
Object[] result = extractor.extract(new String[] { "a", "b", null, "d" });
assertTrue(Arrays.equals(new Object[] { "a", "b", "", "d" }, result));
}
@Test
public void testExtract_collection() {
public void testExtractFieldSet() {
PassThroughFieldExtractor<FieldSet> extractor = new PassThroughFieldExtractor<FieldSet>();
Object[] result = extractor.extract(new DefaultFieldSet(new String[] { "a", "b", "", "d" }));
assertTrue(Arrays.equals(new Object[] { "a", "b", "", "d" }, result));
}
@Test
public void testExtractCollection() {
PassThroughFieldExtractor<List<String>> extractor = new PassThroughFieldExtractor<List<String>>();
Object[] result = extractor.extract(Arrays.asList("a", "b", null, "d"));
assertTrue(Arrays.equals(new Object[] { "a", "b", "", "d" }, result));