REOPENED - issue BATCH-640: FieldSetMapper.mapLine() should contain the line number

This commit is contained in:
dsyer
2008-08-06 22:36:57 +00:00
parent b690c6e92b
commit b9291aff16
27 changed files with 125 additions and 97 deletions

View File

@@ -18,8 +18,6 @@ package org.springframework.batch.item.file;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
@@ -104,23 +102,6 @@ public class FlatFileItemReaderBasicTests extends TestCase {
assertEquals(null, itemReader.read());
}
/**
* Regular usage of <code>read</code> method
*/
public void testReadWithLineNumber() throws Exception {
final List<Integer> list = new ArrayList<Integer>();
itemReader.setFieldSetMapper(new FieldSetMapper<FieldSet>() {
public FieldSet mapLine(FieldSet fs, int lineNum) {
list.add(lineNum);
return fs;
}
});
itemReader.open(executionContext);
assertEquals("[FlatFileInputTemplate-TestData]", itemReader.read().toString());
assertEquals(new Integer(1), list.get(0));
assertEquals(null, itemReader.read());
}
/**
* Regular usage of <code>read</code> method
*/
@@ -142,7 +123,7 @@ public class FlatFileItemReaderBasicTests extends TestCase {
public void testReadWithMapperError() throws Exception {
itemReader.setFieldSetMapper(new FieldSetMapper<FieldSet>() {
public FieldSet mapLine(FieldSet fs, int lineNum) {
public FieldSet mapLine(FieldSet fs) {
throw new RuntimeException("foo");
}
});

View File

@@ -21,7 +21,7 @@ public class FlatFileItemReaderCommonTests extends CommonItemStreamItemReaderTes
Resource resource = new ByteArrayResource(FOOS.getBytes());
tested.setResource(resource);
tested.setFieldSetMapper(new FieldSetMapper<Foo>() {
public Foo mapLine(FieldSet fs, int lineNum) {
public Foo mapLine(FieldSet fs) {
Foo foo = new Foo();
foo.setValue(fs.readInt(0));
return foo;

View File

@@ -23,7 +23,7 @@ public class MultiResourceItemReaderFlatFileTests extends
FlatFileItemReader<Foo> fileReader = new FlatFileItemReader<Foo>();
fileReader.setFieldSetMapper(new FieldSetMapper<Foo>() {
public Foo mapLine(FieldSet fs, int lineNum) {
public Foo mapLine(FieldSet fs) {
Foo foo = new Foo();
foo.setValue(fs.readInt(0));
return foo;

View File

@@ -63,7 +63,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -78,7 +78,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -93,7 +93,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "VarString", "VAR_BOOLEAN", "VAR_CHAR" });
TestObject result = mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -107,7 +107,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -130,7 +130,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
new String[] { "This is some dummy string", "1", "Another dummy", "2" }, new String[] { "valueA",
"valueB", "testObjectB.valueA", "testObjectB.testObjectC.value" });
TestNestedA result = mapper.mapLine(fieldSet, -1);
TestNestedA result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getValueA());
assertEquals(1, result.getValueB());
@@ -150,7 +150,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "1" }, new String[] {
"VALUE_A", "VALUE_B" });
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet, -1);
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getValueA());
assertEquals(1, result.getValueB());
@@ -167,7 +167,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1" }, new String[] { "foo" });
TestNestedC result = mapper.mapLine(fieldSet, -1);
TestNestedC result = mapper.mapLine(fieldSet);
// "foo" is similar enough to "value" that it matches - but only because
// nothing else does...
@@ -189,7 +189,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy", "2" }, new String[] {
"TestObjectB.ValueA", "TestObjectB.TestObjectC.Value" });
TestNestedA result = mapper.mapLine(fieldSet, -1);
TestNestedA result = mapper.mapLine(fieldSet);
assertEquals("Another dummy", result.getTestObjectB().getValueA());
assertEquals(2, result.getTestObjectB().getTestObjectC().getValue());
@@ -209,7 +209,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy" }, new String[] { "TestObjectB.foo" });
try {
mapper.mapLine(fieldSet, -1);
mapper.mapLine(fieldSet);
fail("Expected NotWritablePropertyException");
}
catch (NotWritablePropertyException e) {
@@ -231,7 +231,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "2" }, new String[] { "TestObjectA.garbage" });
try {
mapper.mapLine(fieldSet, -1);
mapper.mapLine(fieldSet);
fail("Expected NotWritablePropertyException");
}
catch (NotWritablePropertyException e) {
@@ -271,7 +271,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1", "2", "3" }, new String[] { "NestedC[0].Value",
"NestedC[1].Value", "NestedC[2].Value" });
mapper.mapLine(fieldSet, -1);
mapper.mapLine(fieldSet);
assertEquals(1, ((TestNestedC) nestedList.getNestedC().get(0)).getValue());
assertEquals(2, ((TestNestedC) nestedList.getNestedC().get(1)).getValue());
@@ -285,7 +285,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
mapper.setTargetType(TestObject.class);
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009" }, new String[] { "varLong" });
TestObject bean = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject bean = (TestObject) mapper.mapLine(fieldSet);
// since Spring 2.5.5 this is OK (before that BATCH-261)
assertEquals(9, bean.getVarLong());
}
@@ -299,7 +299,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
.getNumberInstance(), true)));
TestObject bean = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject bean = (TestObject) mapper.mapLine(fieldSet);
assertEquals(9, bean.getVarLong());
}
@@ -313,7 +313,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
.getNumberInstance(), true)));
TestObject bean = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject bean = (TestObject) mapper.mapLine(fieldSet);
assertEquals(9, bean.getVarLong());
assertEquals(78, bean.getVarInt());

View File

@@ -27,11 +27,11 @@ public class PassThroughFieldSetMapperTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper#mapLine(org.springframework.batch.item.file.mapping.FieldSet, int)}.
* {@link org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper#mapLine(org.springframework.batch.item.file.mapping.FieldSet)}.
*/
public void testMapLine() {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "foo", "bar" });
assertEquals(fieldSet, mapper.mapLine(fieldSet, -1));
assertEquals(fieldSet, mapper.mapLine(fieldSet));
}

View File

@@ -16,26 +16,26 @@ public class AggregateItemFieldSetMapperTests {
@Test
public void testDefaultBeginRecord() throws Exception {
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "BEGIN" }), -1).isHeader());
assertFalse(mapper.mapLine(new DefaultFieldSet(new String[] { "BEGIN" }), -1).isFooter());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "BEGIN" })).isHeader());
assertFalse(mapper.mapLine(new DefaultFieldSet(new String[] { "BEGIN" })).isFooter());
}
@Test
public void testSetBeginRecord() throws Exception {
mapper.setBegin("FOO");
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" }), -1).isHeader());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" })).isHeader());
}
@Test
public void testDefaultEndRecord() throws Exception {
assertFalse(mapper.mapLine(new DefaultFieldSet(new String[] { "END" }), -1).isHeader());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "END" }), -1).isFooter());
assertFalse(mapper.mapLine(new DefaultFieldSet(new String[] { "END" })).isHeader());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "END" })).isFooter());
}
@Test
public void testSetEndRecord() throws Exception {
mapper.setEnd("FOO");
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" }), -1).isFooter());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" })).isFooter());
}
@Test
@@ -52,11 +52,11 @@ public class AggregateItemFieldSetMapperTests {
@Test
public void testDelegate() throws Exception {
mapper.setDelegate(new FieldSetMapper<String>() {
public String mapLine(FieldSet fs, int lineNum) {
public String mapLine(FieldSet fs) {
return "foo";
}
});
assertEquals("foo", mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" }), -1).getItem());
assertEquals("foo", mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" })).getItem());
}

View File

@@ -1,11 +1,11 @@
package org.springframework.batch.item.support;
import java.util.ArrayList;
import java.util.List;
import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import junit.framework.TestCase;
import static org.easymock.EasyMock.*;
import org.springframework.batch.item.ItemWriter;
/**
@@ -28,7 +28,8 @@ public class CompositeItemWriterTests extends TestCase {
final int NUMBER_OF_WRITERS = 10;
Object data = new Object();
List<ItemWriter<Object>> writers = new ArrayList<ItemWriter<Object>>(NUMBER_OF_WRITERS);
@SuppressWarnings("unchecked")
ItemWriter<Object>[] writers = new ItemWriter[NUMBER_OF_WRITERS];
for (int i = 0; i < NUMBER_OF_WRITERS; i++) {
@SuppressWarnings("unchecked")
@@ -38,7 +39,7 @@ public class CompositeItemWriterTests extends TestCase {
expectLastCall().once();
replay(writer);
writers.add(writer);
writers[i] = writer;
}
itemProcessor.setDelegates(writers);

View File

@@ -60,7 +60,7 @@ public abstract class AbstractTradeBatchTests extends TestCase {
}
protected static class TradeMapper implements FieldSetMapper<Trade> {
public Trade mapLine(FieldSet fs, int lineNum) {
public Trade mapLine(FieldSet fs) {
return new Trade(fs);
}
}