diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java index ae49f83c2..11f01b556 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java @@ -37,14 +37,14 @@ public class ExecutionContext implements Serializable { private boolean dirty = false; - private final Map map; + private final Map map; /** * Default constructor. Initializes a new execution context with an empty * internal map. */ public ExecutionContext() { - map = new HashMap(); + map = new HashMap(); } /** @@ -52,7 +52,7 @@ public class ExecutionContext implements Serializable { * * @param map Initial contents of context. */ - public ExecutionContext(Map map) { + public ExecutionContext(Map map) { this.map = map; } @@ -64,7 +64,7 @@ public class ExecutionContext implements Serializable { if (executionContext == null) { return; } - for (Entry entry : executionContext.entrySet()) { + for (Entry entry : executionContext.entrySet()) { this.map.put(entry.getKey(), entry.getValue()); } } @@ -265,7 +265,7 @@ public class ExecutionContext implements Serializable { * @return A set representing the contents of the context * @see java.util.Map#entrySet() */ - public Set> entrySet() { + public Set> entrySet() { return map.entrySet(); } @@ -302,8 +302,8 @@ public class ExecutionContext implements Serializable { */ public Properties getProperties() { Properties props = new Properties(); - for (Entry entry : map.entrySet()) { - props.setProperty(entry.getKey().toString(), entry.getValue().toString()); + for (Entry entry : map.entrySet()) { + props.setProperty(entry.getKey(), entry.getValue().toString()); } return props; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java index 20f28ddbc..63ab91df9 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java @@ -19,7 +19,6 @@ package org.springframework.batch.item.file.mapping; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -86,7 +85,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im private BeanFactory beanFactory; - private static Map propertiesMatched = new HashMap(); + private static Map, Map> propertiesMatched = new HashMap, Map>(); private static int distanceLimit = 5; @@ -126,7 +125,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im * * @param type the type to set */ - public void setTargetType(Class type) { + public void setTargetType(Class type) { this.type = type; } @@ -227,23 +226,23 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im * @param properties * @return */ + @SuppressWarnings("unchecked") private Properties getBeanProperties(Object bean, Properties properties) { - Class cls = bean.getClass(); + Class cls = bean.getClass(); // Map from field names to property names - Map matches = (Map) propertiesMatched.get(cls); + Map matches = propertiesMatched.get(cls); if (matches == null) { - matches = new HashMap(); + matches = new HashMap(); propertiesMatched.put(cls, matches); } - Set keys = new HashSet(properties.keySet()); - for (Iterator iter = keys.iterator(); iter.hasNext();) { - String key = (String) iter.next(); + Set keys = new HashSet(properties.keySet()); + for (String key : keys) { if (matches.containsKey(key)) { - switchPropertyNames(properties, key, (String) matches.get(key)); + switchPropertyNames(properties, key, matches.get(key)); continue; } @@ -260,7 +259,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im private String findPropertyName(Object bean, String key) { - Class cls = bean.getClass(); + Class cls = bean.getClass(); int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(key); String prefix; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/DrivingQueryItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/DrivingQueryItemReaderTests.java index ad5d064bb..effe26d1d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/DrivingQueryItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/DrivingQueryItemReaderTests.java @@ -128,7 +128,7 @@ public class DrivingQueryItemReaderTests extends TestCase { * @throws Exception */ public void testRestoreFromEmptyData() throws Exception { - ExecutionContext streamContext = new ExecutionContext(new Properties()); + ExecutionContext streamContext = new ExecutionContext(new ExecutionContext()); getAsItemStream(itemReader).open(streamContext); @@ -201,11 +201,9 @@ public class DrivingQueryItemReaderTests extends TestCase { static final String RESTART_KEY = "restart.keys"; static { - Properties props = new Properties(); // restart data properties cannot be empty. - props.setProperty("", ""); - - streamContext = new ExecutionContext(props); + streamContext = new ExecutionContext(); + streamContext.put("", ""); } public MockKeyGenerator() { diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/StepExecutionMessageHandlerTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/StepExecutionMessageHandlerTests.java index e7c8a3827..76a6791b6 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/StepExecutionMessageHandlerTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/StepExecutionMessageHandlerTests.java @@ -49,7 +49,8 @@ public class StepExecutionMessageHandlerTests { /** * Test method for - * {@link org.springframework.batch.integration.job.StepExecutionMessageHandler#setStep(org.springframework.batch.core.Step)}. + * {@link org.springframework.batch.integration.job.StepExecutionMessageHandler#setStep(org.springframework.batch.core.Step)} + * . */ @Test public void testSetStep() { @@ -63,7 +64,8 @@ public class StepExecutionMessageHandlerTests { /** * Test method for - * {@link org.springframework.batch.integration.job.StepExecutionMessageHandler#setJobRepository(org.springframework.batch.core.repository.JobRepository)}. + * {@link org.springframework.batch.integration.job.StepExecutionMessageHandler#setJobRepository(org.springframework.batch.core.repository.JobRepository)} + * . */ @Test public void testSetJobRepository() { @@ -97,7 +99,7 @@ public class StepExecutionMessageHandlerTests { JobExecutionRequest message = handler.handle(jobExecutionRequest); assertEquals(1, message.getJobExecution().getStepExecutions().size()); JobExecution jobExecution = message.getJobExecution(); - assertTrue(jobExecution .getExecutionContext().containsKey("foo")); + assertTrue(jobExecution.getExecutionContext().containsKey("foo")); } @SuppressWarnings("unchecked") @@ -117,8 +119,8 @@ public class StepExecutionMessageHandlerTests { }); JobExecutionRequest message = handler.handle(jobExecutionRequest); JobExecution jobExecution = message.getJobExecution(); - assertTrue(jobExecution .getExecutionContext().containsKey("foo")); - assertTrue(jobExecution .getExecutionContext().containsKey("bar")); + assertTrue(jobExecution.getExecutionContext().containsKey("foo")); + assertTrue(jobExecution.getExecutionContext().containsKey("bar")); } @SuppressWarnings("unchecked") @@ -140,14 +142,20 @@ public class StepExecutionMessageHandlerTests { public StepExecution getLastStepExecution(JobInstance jobInstance, Step step) { StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance)); stepExecution.setStatus(BatchStatus.FAILED); - stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter - .stringToProperties("foo=bar"))); + stepExecution.setExecutionContext(new ExecutionContext() { + { + put("foo", "bar"); + } + }); + return stepExecution; } /* * (non-Javadoc) - * @see org.springframework.integration.batch.JobRepositorySupport#getStepExecutionCount(org.springframework.batch.core.JobInstance, + * + * @seeorg.springframework.integration.batch.JobRepositorySupport# + * getStepExecutionCount(org.springframework.batch.core.JobInstance, * org.springframework.batch.core.Step) */ @Override @@ -172,8 +180,11 @@ public class StepExecutionMessageHandlerTests { public StepExecution getLastStepExecution(JobInstance jobInstance, Step step) { StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance)); stepExecution.setStatus(BatchStatus.COMPLETED); - stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter - .stringToProperties("foo=bar"))); + stepExecution.setExecutionContext(new ExecutionContext() { + { + put("foo", "bar"); + } + }); return stepExecution; } };