Removed warnings from AggregateItemReaderTests
This commit is contained in:
@@ -24,15 +24,14 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.MarkFailedException;
|
||||
import org.springframework.batch.item.ResetFailedException;
|
||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
|
||||
/**
|
||||
* An {@link ItemReader} that delivers a list as its item, storing up objects
|
||||
* from the injected {@link ItemReader} until they are ready to be packed out as
|
||||
* a collection. The {@link ItemReader} should mark the beginning and end of
|
||||
* records with the constant values in {@link FieldSetMapper} (
|
||||
* {@link AggregateItemReader#BEGIN_RECORD} and
|
||||
* {@link AggregateItemReader#END_RECORD}).<br/>
|
||||
* a collection. Usually this class will be used as a wrapper for a custom
|
||||
* {@link ItemReader} that can identify the record boundaries. The custom reader
|
||||
* should mark the beginning and end of records with the constant values ({@link AggregateItemReader#BEGIN_RECORD}
|
||||
* and {@link AggregateItemReader#END_RECORD}).<br/>
|
||||
*
|
||||
* This class is thread safe (it can be used concurrently by multiple threads)
|
||||
* as long as the {@link ItemReader} is also thread safe.
|
||||
@@ -124,7 +123,6 @@ public class AggregateItemReader implements ItemReader<List<?>> {
|
||||
*/
|
||||
private class ResultHolder {
|
||||
List<Object> records = new ArrayList<Object>();
|
||||
|
||||
boolean exhausted = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +1,60 @@
|
||||
package org.springframework.batch.item.support;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.support.AggregateItemReader;
|
||||
|
||||
public class AggregateItemReaderTests extends TestCase {
|
||||
|
||||
private MockControl inputControl;
|
||||
private ItemReader<Object> input;
|
||||
|
||||
private AggregateItemReader provider;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
// create mock for input
|
||||
input = new AbstractItemReader<Object>() {
|
||||
|
||||
//create mock for input
|
||||
inputControl = MockControl.createControl(ItemReader.class);
|
||||
input = (ItemReader<Object>) inputControl.getMock();
|
||||
private int count = 0;
|
||||
|
||||
//create provider
|
||||
public Object read() {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
return AggregateItemReader.BEGIN_RECORD;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return "line";
|
||||
case 4:
|
||||
return AggregateItemReader.END_RECORD;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
// create provider
|
||||
provider = new AggregateItemReader();
|
||||
provider.setItemReader(input);
|
||||
}
|
||||
|
||||
public void testNext() throws Exception {
|
||||
|
||||
//set-up mock input
|
||||
input.read();
|
||||
inputControl.setReturnValue(AggregateItemReader.BEGIN_RECORD);
|
||||
input.read();
|
||||
inputControl.setReturnValue("line",3);
|
||||
input.read();
|
||||
inputControl.setReturnValue(AggregateItemReader.END_RECORD);
|
||||
input.read();
|
||||
inputControl.setReturnValue(null);
|
||||
inputControl.replay();
|
||||
|
||||
//read object
|
||||
// read object
|
||||
Object result = provider.read();
|
||||
|
||||
//it should be collection of 3 strings "line"
|
||||
// it should be collection of 3 strings "line"
|
||||
assertTrue(result instanceof Collection);
|
||||
Collection<?> lines = (Collection<?>)result;
|
||||
Collection<?> lines = (Collection<?>) result;
|
||||
assertEquals(3, lines.size());
|
||||
|
||||
for (Iterator<?> i = lines.iterator(); i.hasNext();) {
|
||||
assertEquals("line", i.next());
|
||||
for (Object line : lines) {
|
||||
assertEquals("line", line);
|
||||
}
|
||||
|
||||
//read object again - it should return null
|
||||
// read object again - it should return null
|
||||
assertNull(provider.read());
|
||||
|
||||
//verify method calls
|
||||
inputControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user