IN PROGRESS - BATCH-709: Change all collections to use generics
This commit is contained in:
@@ -3,6 +3,7 @@ package org.springframework.batch.item.adapter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.sample.FooService;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
@@ -25,13 +26,13 @@ public class ItemReaderAdapterTests extends AbstractDependencyInjectionSpringCon
|
||||
* Regular usage scenario - items are retrieved from the service injected invoker points to.
|
||||
*/
|
||||
public void testNext() throws Exception {
|
||||
List returnedItems = new ArrayList();
|
||||
List<Object> returnedItems = new ArrayList<Object>();
|
||||
Object item;
|
||||
while ((item = provider.read()) != null) {
|
||||
returnedItems.add(item);
|
||||
}
|
||||
|
||||
List input = fooService.getGeneratedFoos();
|
||||
List<Foo> input = fooService.getGeneratedFoos();
|
||||
assertEquals(input.size(), returnedItems.size());
|
||||
assertFalse(returnedItems.isEmpty());
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ public class ItemWriterAdapterTests extends AbstractDependencyInjectionSpringCon
|
||||
processor.write(foo);
|
||||
}
|
||||
|
||||
List input = fooService.getGeneratedFoos();
|
||||
List processed = fooService.getProcessedFoos();
|
||||
List<Foo> input = fooService.getGeneratedFoos();
|
||||
List<Foo> processed = fooService.getProcessedFoos();
|
||||
assertEquals(input.size(), processed.size());
|
||||
assertFalse(fooService.getProcessedFoos().isEmpty());
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ public class PropertyExtractingDelegatingItemProccessorIntegrationTests extends
|
||||
processor.write(foo);
|
||||
}
|
||||
|
||||
List input = fooService.getGeneratedFoos();
|
||||
List processed = fooService.getProcessedFooNameValuePairs();
|
||||
List<Foo> input = fooService.getGeneratedFoos();
|
||||
List<Foo> processed = fooService.getProcessedFooNameValuePairs();
|
||||
assertEquals(input.size(), processed.size());
|
||||
assertFalse(fooService.getProcessedFooNameValuePairs().isEmpty());
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
protected List list = new ArrayList();
|
||||
protected List<Object> list = new ArrayList<Object>();
|
||||
|
||||
private RepeatContext context = new RepeatContextSupport(null);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
|
||||
list.add(item);
|
||||
}
|
||||
});
|
||||
TransactionSynchronizationManager.bindResource(writer.getResourceKey(), new HashSet(
|
||||
TransactionSynchronizationManager.bindResource(writer.getResourceKey(), new HashSet<Object>(
|
||||
Collections.singleton("spam")));
|
||||
RepeatSynchronizationManager.register(context);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CompositeKeyFooDao extends JdbcDaoSupport implements FooDao {
|
||||
*/
|
||||
public Foo getFoo(Object key) {
|
||||
|
||||
Map keys = (Map)key;
|
||||
Map<?,?> keys = (Map<?,?>)key;
|
||||
Object[] args = keys.values().toArray();
|
||||
|
||||
RowMapper fooMapper = new RowMapper(){
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.springframework.batch.item.database;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -162,8 +161,8 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
|
||||
itemReader.setKeyCollector(new KeyCollector() {
|
||||
|
||||
public List retrieveKeys(ExecutionContext executionContext) {
|
||||
return new ArrayList();
|
||||
public List<Object> retrieveKeys(ExecutionContext executionContext) {
|
||||
return new ArrayList<Object>();
|
||||
}
|
||||
|
||||
public void updateContext(Object key,
|
||||
@@ -196,8 +195,8 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
private static class MockKeyGenerator implements KeyCollector {
|
||||
|
||||
static ExecutionContext streamContext;
|
||||
List keys;
|
||||
List restartKeys;
|
||||
List<Object> keys;
|
||||
List<Object> restartKeys;
|
||||
static final String RESTART_KEY = "restart.keys";
|
||||
|
||||
static {
|
||||
@@ -208,14 +207,14 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
|
||||
public MockKeyGenerator() {
|
||||
|
||||
keys = new ArrayList();
|
||||
keys = new ArrayList<Object>();
|
||||
keys.add(new Foo(1, "1", 1));
|
||||
keys.add(new Foo(2, "2", 2));
|
||||
keys.add(new Foo(3, "3", 3));
|
||||
keys.add(new Foo(4, "4", 4));
|
||||
keys.add(new Foo(5, "5", 5));
|
||||
|
||||
restartKeys = new ArrayList();
|
||||
restartKeys = new ArrayList<Object>();
|
||||
restartKeys.add(new Foo(3, "3", 3));
|
||||
restartKeys.add(new Foo(4, "4", 4));
|
||||
restartKeys.add(new Foo(5, "5", 5));
|
||||
@@ -225,7 +224,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
return streamContext;
|
||||
}
|
||||
|
||||
public List retrieveKeys(ExecutionContext executionContext) {
|
||||
public List<Object> retrieveKeys(ExecutionContext executionContext) {
|
||||
if (executionContext.containsKey(RESTART_KEY)) {
|
||||
return restartKeys;
|
||||
} else {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class HibernateAwareItemWriterTests extends TestCase {
|
||||
|
||||
HibernateAwareItemWriter writer = new HibernateAwareItemWriter();
|
||||
|
||||
final List list = new ArrayList();
|
||||
final List<Object> list = new ArrayList<Object>();
|
||||
|
||||
private RepeatContextSupport context;
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ public class ColumnMapExecutionContextRowMapperTests extends TestCase {
|
||||
|
||||
private ColumnMapItemPreparedStatementSetter mapper;
|
||||
|
||||
private Map key;
|
||||
private Map<Object, Object> key;
|
||||
|
||||
private MockControl psControl = MockControl.createControl(PreparedStatement.class);
|
||||
private PreparedStatement ps;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
@@ -58,7 +59,7 @@ public class ColumnMapExecutionContextRowMapperTests extends TestCase {
|
||||
public void testCreateExecutionContextFromEmptyKeys() throws Exception {
|
||||
|
||||
psControl.replay();
|
||||
mapper.setValues(new HashMap(), ps);
|
||||
mapper.setValues(new HashMap<Object, Object>(), ps);
|
||||
psControl.verify();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
|
||||
public void testRetrieveKeys(){
|
||||
|
||||
List keys = keyStrategy.retrieveKeys(executionContext);
|
||||
List<Object> keys = keyStrategy.retrieveKeys(executionContext);
|
||||
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
Map id = (Map)keys.get(i);
|
||||
Map<?,?> id = (Map<?,?>)keys.get(i);
|
||||
assertEquals(id.get("ID"), new Long(i + 1));
|
||||
assertEquals(id.get("VALUE"), new Integer(i + 1));
|
||||
}
|
||||
@@ -49,53 +49,22 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
|
||||
public void testRestoreKeys(){
|
||||
|
||||
Map keyMap = new LinkedHashMap();
|
||||
Map<String, String> keyMap = new LinkedHashMap<String, String>();
|
||||
keyMap.put("ID", "3");
|
||||
keyMap.put("VALUE", "3");
|
||||
executionContext.put(ClassUtils.getShortName(MultipleColumnJdbcKeyCollector.class)+ ".current.key", keyMap);
|
||||
|
||||
List keys = keyStrategy.retrieveKeys(executionContext);
|
||||
List<Object> keys = keyStrategy.retrieveKeys(executionContext);
|
||||
|
||||
assertEquals(2, keys.size());
|
||||
Map key = (Map)keys.get(0);
|
||||
Map<?,?> key = (Map<?,?>)keys.get(0);
|
||||
assertEquals(new Long(4), key.get("ID"));
|
||||
assertEquals(new Integer(4), key.get("VALUE"));
|
||||
key = (Map)keys.get(1);
|
||||
key = (Map<?,?>)keys.get(1);
|
||||
assertEquals(new Long(5), key.get("ID"));
|
||||
assertEquals(new Integer(5), key.get("VALUE"));
|
||||
}
|
||||
|
||||
// public void testGetKeyAsExecutionContext(){
|
||||
//
|
||||
// Map key = CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(1);
|
||||
// key.put("ID", new Long(3));
|
||||
// key.put("VALUE", new Integer(4));
|
||||
//
|
||||
// keyStrategy.setKeyMapper(new KeyMappingPreparedStatementSetter() {
|
||||
// public PreparedStatementSetter createSetter(ExecutionContext executionContext) {
|
||||
// return null;
|
||||
// }
|
||||
// public void mapKeys(Object key, ExecutionContext executionContext) {
|
||||
// // Just slap the key as a map into the context
|
||||
// Map keys = (Map) key;
|
||||
// for (Iterator it = keys.entrySet().iterator(); it.hasNext();) {
|
||||
// Entry entry = (Entry)it.next();
|
||||
// executionContext.put(entry.getKey().toString(), entry.getValue());
|
||||
// }
|
||||
// }
|
||||
// public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
// return null;
|
||||
// }
|
||||
// });
|
||||
// keyStrategy.updateContext(key, executionContext);
|
||||
// Properties props = executionContext.getProperties();
|
||||
//
|
||||
// assertEquals(2, props.size());
|
||||
// System.err.println(props);
|
||||
// assertEquals("3", props.get("ID"));
|
||||
// assertEquals("4", props.get("VALUE"));
|
||||
// }
|
||||
|
||||
public void testGetNullKeyAsStreamContext(){
|
||||
|
||||
try{
|
||||
|
||||
@@ -35,7 +35,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
|
||||
|
||||
public void testRetrieveKeys(){
|
||||
|
||||
List keys = keyStrategy.retrieveKeys(new ExecutionContext());
|
||||
List<Object> keys = keyStrategy.retrieveKeys(new ExecutionContext());
|
||||
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
Long id = (Long)keys.get(i);
|
||||
@@ -51,7 +51,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
|
||||
|
||||
keyStrategy.updateContext(new Long(3), executionContext);
|
||||
|
||||
List keys = keyStrategy.retrieveKeys(executionContext);
|
||||
List<Object> keys = keyStrategy.retrieveKeys(executionContext);
|
||||
|
||||
assertEquals(2, keys.size());
|
||||
assertEquals(new Long(4), keys.get(0));
|
||||
|
||||
@@ -16,9 +16,9 @@ public class FooService {
|
||||
public static final int GENERATION_LIMIT = 10;
|
||||
|
||||
private int counter = 0;
|
||||
private List generatedFoos = new ArrayList(GENERATION_LIMIT);
|
||||
private List processedFoos = new ArrayList(GENERATION_LIMIT);
|
||||
private List processedFooNameValuePairs = new ArrayList(GENERATION_LIMIT);
|
||||
private List<Foo> generatedFoos = new ArrayList<Foo>(GENERATION_LIMIT);
|
||||
private List<Foo> processedFoos = new ArrayList<Foo>(GENERATION_LIMIT);
|
||||
private List<Foo> processedFooNameValuePairs = new ArrayList<Foo>(GENERATION_LIMIT);
|
||||
|
||||
public Foo generateFoo() {
|
||||
if (counter++ >= GENERATION_LIMIT) return null;
|
||||
@@ -37,15 +37,15 @@ public class FooService {
|
||||
processedFooNameValuePairs.add(new Foo(0, name, value));
|
||||
}
|
||||
|
||||
public List getGeneratedFoos() {
|
||||
public List<Foo> getGeneratedFoos() {
|
||||
return generatedFoos;
|
||||
}
|
||||
|
||||
public List getProcessedFoos() {
|
||||
public List<Foo> getProcessedFoos() {
|
||||
return processedFoos;
|
||||
}
|
||||
|
||||
public List getProcessedFooNameValuePairs() {
|
||||
public List<Foo> getProcessedFooNameValuePairs() {
|
||||
return processedFooNameValuePairs;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user