diff --git a/build.gradle b/build.gradle index 7518ef85c..bd0a382ce 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { environmentProperty = project.hasProperty('environment') ? getProperty('environment') : 'hsql' - springVersionDefault = '5.0.0.M5' + springVersionDefault = '5.0.0.BUILD-SNAPSHOT' springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : springVersionDefault springRetryVersion = '1.2.0.RELEASE' springAmqpVersion = '1.5.6.RELEASE' @@ -58,7 +58,7 @@ allprojects { springDataMongodbVersion = '2.0.0.BUILD-SNAPSHOT' springDataNeo4jVersion = '5.0.0.BUILD-SNAPSHOT' springIntegrationVersion = '5.0.0.M1' - springLdapVersion = '2.0.4.RELEASE' + springLdapVersion = '2.3.1.RELEASE' activemqVersion = '5.13.2' aspectjVersion = '1.8.9' diff --git a/spring-batch-core-tests/src/test/java/org/springframework/batch/core/test/ldif/MappingLdifReaderTests.java b/spring-batch-core-tests/src/test/java/org/springframework/batch/core/test/ldif/MappingLdifReaderTests.java index 4308859a6..c71ed5777 100644 --- a/spring-batch-core-tests/src/test/java/org/springframework/batch/core/test/ldif/MappingLdifReaderTests.java +++ b/spring-batch-core-tests/src/test/java/org/springframework/batch/core/test/ldif/MappingLdifReaderTests.java @@ -15,11 +15,18 @@ */ package org.springframework.batch.core.test.ldif; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.net.MalformedURLException; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; @@ -34,12 +41,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Assert; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.net.MalformedURLException; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/applicationContext-test2.xml"}) public class MappingLdifReaderTests { @@ -78,7 +79,7 @@ public class MappingLdifReaderTests { //Check output. Assert.isTrue(actual.exists(), "Actual does not exist."); - Assert.isTrue(compareFiles(expected.getFile(), actual.getFile())); + Assert.isTrue(compareFiles(expected.getFile(), actual.getFile()), "Files were not equal"); } @Test diff --git a/spring-batch-core-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-core-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index 5fa3a7977..e974ad0e9 100644 --- a/spring-batch-core-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-core-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -79,7 +79,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource); + Assert.notNull(dataSource, "A DataSource is required"); logger.info("Initializing with scripts: "+Arrays.asList(initScripts)); if (!initialized && initialize) { try { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobInstance.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobInstance.java index 54f04cb1d..e0dfecd19 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobInstance.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobInstance.java @@ -45,7 +45,7 @@ public class JobInstance extends Entity implements javax.batch.runtime.JobInstan public JobInstance(Long id, String jobName) { super(id); - Assert.hasLength(jobName); + Assert.hasLength(jobName, "A jobName is required"); this.jobName = jobName; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java index f53e8036d..c77a17193 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java @@ -97,7 +97,7 @@ public class StepExecution extends Entity { */ public StepExecution(String stepName, JobExecution jobExecution) { super(); - Assert.hasLength(stepName); + Assert.hasLength(stepName, "A stepName is required"); this.stepName = stepName; this.jobExecution = jobExecution; } @@ -112,7 +112,7 @@ public class StepExecution extends Entity { @SuppressWarnings("unused") private StepExecution(String stepName) { super(); - Assert.hasLength(stepName); + Assert.hasLength(stepName, "A stepName is required"); this.stepName = stepName; this.jobExecution = null; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/BatchConfigurationException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/BatchConfigurationException.java index 6b1da62a6..a0e1641f6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/BatchConfigurationException.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/BatchConfigurationException.java @@ -25,6 +25,8 @@ package org.springframework.batch.core.configuration; */ public class BatchConfigurationException extends RuntimeException { + private static final long serialVersionUID = 1L; + /** * @param t an exception to be wrapped */ diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClasspathXmlApplicationContextsFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClasspathXmlApplicationContextsFactoryBean.java index 9e4d7fb5e..e9fd79321 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClasspathXmlApplicationContextsFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClasspathXmlApplicationContextsFactoryBean.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; @@ -57,7 +56,7 @@ public class ClasspathXmlApplicationContextsFactoryBean implements FactoryBeanclasspath*:/config/*-context.xml). * - * @param resources + * @param resources array of resources to use */ public void setResources(Resource[] resources) { this.resources = Arrays.asList(resources); @@ -105,7 +104,6 @@ public class ClasspathXmlApplicationContextsFactoryBean implements FactoryBean applicationContextFactories = new ArrayList(); + List applicationContextFactories = new ArrayList<>(); for (Resource resource : resources) { GenericApplicationContextFactory factory = new GenericApplicationContextFactory(resource); factory.setCopyConfiguration(copyConfiguration); @@ -158,7 +156,6 @@ public class ClasspathXmlApplicationContextsFactoryBean implements FactoryBean findReachableElements(Element element) { @@ -208,8 +209,8 @@ public abstract class AbstractFlowParser extends AbstractSingleBeanDefinitionPar /** * Find all of the elements reachable from the startElement. * - * @param startElement - * @param reachableElementMap + * @param startElement name of the element to start from + * @param reachableElementMap Map of elements that can be reached from the startElement * @param accumulator a collection of reachable element names */ protected void findAllReachableElements(String startElement, Map> reachableElementMap, diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java index 8d33cb0b1..f17052fc6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java @@ -15,6 +15,10 @@ */ package org.springframework.batch.core.configuration.xml; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + import org.springframework.batch.core.listener.StepListenerMetaData; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.BeanDefinition; @@ -28,9 +32,6 @@ import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; /** * Internal parser for the <step/> elements inside a job. A step element @@ -89,7 +90,7 @@ public abstract class AbstractStepParser { /** * @param stepElement The <step/> element - * @param parserContext + * @param parserContext context * @param jobFactoryRef the reference to the {@link JobParserJobFactoryBean} * from the enclosing tag. Use 'null' if unknown. */ diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/ChunkElementParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/ChunkElementParser.java index 693b52c05..fe93f7961 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/ChunkElementParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/ChunkElementParser.java @@ -17,6 +17,8 @@ package org.springframework.batch.core.configuration.xml; import java.util.List; +import org.w3c.dom.Element; + import org.springframework.batch.core.listener.StepListenerMetaData; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.beans.BeanMetadataElement; @@ -35,7 +37,6 @@ import org.springframework.beans.factory.xml.ParserContext; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; -import org.w3c.dom.Element; /** * Internal parser for the <chunk/> element inside a step. @@ -67,8 +68,8 @@ public class ChunkElementParser { StepListenerMetaData.itemListenerMetaData()); /** - * @param element - * @param parserContext + * @param element the element to parse + * @param parserContext the context to use */ protected void parse(Element element, AbstractBeanDefinition bd, ParserContext parserContext, boolean underspecified) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index 13de19049..87ed5ad32 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -85,7 +85,7 @@ InitializingBean { * Convenience constructor to immediately add name (which is mandatory but * not final). * - * @param name + * @param name name of the job */ public AbstractJob(String name) { super(); @@ -154,7 +154,7 @@ InitializingBean { * Retrieve the step with the given name. If there is no Step with the given * name, then return null. * - * @param stepName + * @param stepName name of the step * @return the Step */ @Override @@ -242,7 +242,7 @@ InitializingBean { * state of the batch meta domain (jobs, steps, executions) during the life * of a job. * - * @param jobRepository + * @param jobRepository repository to use during the job execution */ public void setJobRepository(JobRepository jobRepository) { this.jobRepository = jobRepository; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/StepState.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/StepState.java index b69e9d068..aef9f3176 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/StepState.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/StepState.java @@ -67,11 +67,7 @@ public class StepState extends AbstractState implements StepLocator, StepHolder return new FlowExecutionStatus(executor.executeStep(step)); } - /** - * @deprecated in favor of using {@link StepLocator#getStep(String)}. - */ @Override - @Deprecated public Step getStep() { return step; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/JobListenerAdapter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/JobListenerAdapter.java index afdadeb29..570e1c0de 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/JobListenerAdapter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/JobListenerAdapter.java @@ -37,7 +37,7 @@ public class JobListenerAdapter implements JobExecutionListener { * @param delegate to be delegated to */ public JobListenerAdapter(JobListener delegate) { - Assert.notNull(delegate); + Assert.notNull(delegate, "Delegate is required"); this.delegate = delegate; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/BatchletStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/BatchletStep.java index 35842893b..877608bf4 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/BatchletStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/BatchletStep.java @@ -39,7 +39,7 @@ public class BatchletStep extends TaskletStep { */ public BatchletStep(String name, BatchPropertyContext propertyContext) { super(name); - Assert.notNull(propertyContext); + Assert.notNull(propertyContext, "A propertyContext is required"); this.propertyContext = propertyContext; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java index b25f99237..5ab100fcf 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java @@ -15,8 +15,22 @@ */ package org.springframework.batch.core.launch.support; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; @@ -44,19 +58,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - /** *

* Basic launcher for starting jobs from the command line. In general, it is diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java index d698dc245..b5b0f0551 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java @@ -15,9 +15,6 @@ */ package org.springframework.batch.core.listener; -import static org.springframework.batch.support.MethodInvokerUtils.getMethodInvokerByAnnotation; -import static org.springframework.batch.support.MethodInvokerUtils.getMethodInvokerForInterface; - import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -26,6 +23,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.aop.TargetSource; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; @@ -37,6 +35,9 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.core.Ordered; import org.springframework.util.Assert; +import static org.springframework.batch.support.MethodInvokerUtils.getMethodInvokerByAnnotation; +import static org.springframework.batch.support.MethodInvokerUtils.getMethodInvokerForInterface; + /** * {@link FactoryBean} implementation that builds a listener based on the * various lifecycle methods or annotations that are provided. There are three @@ -157,7 +158,10 @@ public abstract class AbstractListenerFactoryBean implements FactoryBean context, OutputStream out) throws IOException { - Assert.notNull(context); - Assert.notNull(out); + Assert.notNull(context, "context is required"); + Assert.notNull(out, "OutputStream is required"); for(Object value : context.values()) { - Assert.notNull(value); + Assert.notNull(value, "A null value was found"); if (!(value instanceof Serializable)) { throw new IllegalArgumentException( "Value: [ " + value + "must be serializable." diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java index 753f990ec..6233cfeca 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java @@ -15,19 +15,20 @@ */ package org.springframework.batch.core.repository.dao; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.batch.core.repository.ExecutionContextSerializer; -import org.springframework.util.Assert; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.springframework.batch.core.repository.ExecutionContextSerializer; +import org.springframework.util.Assert; + /** * Implementation that uses Jackson2 to provide (de)serialization. * @@ -60,8 +61,8 @@ public class Jackson2ExecutionContextStringSerializer implements ExecutionContex public void serialize(Map context, OutputStream out) throws IOException { - Assert.notNull(context); - Assert.notNull(out); + Assert.notNull(context, "A context is required"); + Assert.notNull(out, "An OutputStream is required"); objectMapper.writeValue(out, context); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java index 0c89f028b..734881f64 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java @@ -172,7 +172,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements */ private void validateJobExecution(JobExecution jobExecution) { - Assert.notNull(jobExecution); + Assert.notNull(jobExecution, "jobExecution cannot be null"); Assert.notNull(jobExecution.getJobId(), "JobExecution Job-Id cannot be null."); Assert.notNull(jobExecution.getStatus(), "JobExecution status cannot be null."); Assert.notNull(jobExecution.getCreateTime(), "JobExecution create time cannot be null"); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java index 441ff2d0d..1d618c5f3 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java @@ -153,7 +153,7 @@ JobInstanceDao, InitializingBean { if (instances.isEmpty()) { return null; } else { - Assert.state(instances.size() == 1); + Assert.state(instances.size() == 1, "instance counte must be 1 but was " + instances.size()); return instances.get(0); } } @@ -282,7 +282,7 @@ JobInstanceDao, InitializingBean { @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(jobIncrementer); + Assert.notNull(jobIncrementer, "JobIncrementer is required"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index 1a8082470..3cec3edcc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -211,7 +211,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement * @throws IllegalArgumentException */ private void validateStepExecution(StepExecution stepExecution) { - Assert.notNull(stepExecution); + Assert.notNull(stepExecution, "stepExecution is required"); Assert.notNull(stepExecution.getStepName(), "StepExecution step name cannot be null."); Assert.notNull(stepExecution.getStartTime(), "StepExecution start time cannot be null."); Assert.notNull(stepExecution.getStatus(), "StepExecution status cannot be null."); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java index cef950b0e..b037297cd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java @@ -53,7 +53,7 @@ public class MapJobExecutionDao implements JobExecutionDao { @Override public void saveJobExecution(JobExecution jobExecution) { - Assert.isTrue(jobExecution.getId() == null); + Assert.isTrue(jobExecution.getId() == null, "jobExecution id is not null"); Long newId = currentId.getAndIncrement(); jobExecution.setId(newId); jobExecution.incrementVersion(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java index fbfee278d..fda49cb40 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java @@ -68,8 +68,8 @@ public class MapStepExecutionDao implements StepExecutionDao { @Override public void saveStepExecution(StepExecution stepExecution) { - Assert.isTrue(stepExecution.getId() == null); - Assert.isTrue(stepExecution.getVersion() == null); + Assert.isTrue(stepExecution.getId() == null, "stepExecution id was not null"); + Assert.isTrue(stepExecution.getVersion() == null, "stepExecution version was not null"); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); Map executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); @@ -89,7 +89,7 @@ public class MapStepExecutionDao implements StepExecutionDao { @Override public void updateStepExecution(StepExecution stepExecution) { - Assert.notNull(stepExecution.getJobExecutionId()); + Assert.notNull(stepExecution.getJobExecutionId(), "jobExecution id is null"); Map executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); Assert.notNull(executions, "step executions for given job execution are expected to be already saved"); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/XStreamExecutionContextStringSerializer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/XStreamExecutionContextStringSerializer.java index b5b21dc03..aef0bd75b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/XStreamExecutionContextStringSerializer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/XStreamExecutionContextStringSerializer.java @@ -45,6 +45,7 @@ import org.springframework.util.Assert; * versions, this serializer is depricated in favor of * {@link Jackson2ExecutionContextStringSerializer} */ +@Deprecated public class XStreamExecutionContextStringSerializer implements ExecutionContextSerializer, InitializingBean { private ReflectionProvider reflectionProvider = null; @@ -87,8 +88,8 @@ public class XStreamExecutionContextStringSerializer implements ExecutionContext */ @Override public void serialize(Map context, OutputStream out) throws IOException { - Assert.notNull(context); - Assert.notNull(out); + Assert.notNull(context, "context is required"); + Assert.notNull(out, "An OutputStream is required"); out.write(xstream.toXML(context).getBytes()); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java index 52bcb2510..78b5e5259 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java @@ -136,7 +136,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw /** * Convenient constructor for setting only the name property. * - * @param name + * @param name Name of the step */ public AbstractStep(String name) { this.name = name; @@ -147,7 +147,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw * {@link StepExecution} before returning. * * @param stepExecution the current step context - * @throws Exception + * @throws Exception checked exception thrown by implementation */ protected abstract void doExecute(StepExecution stepExecution) throws Exception; @@ -156,7 +156,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw * acquire resources. Does nothing by default. * * @param ctx the {@link ExecutionContext} to use - * @throws Exception + * @throws Exception checked exception thrown by implementation */ protected void open(ExecutionContext ctx) throws Exception { } @@ -166,7 +166,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw * of the finally block), to close or release resources. Does nothing by default. * * @param ctx the {@link ExecutionContext} to use - * @throws Exception + * @throws Exception checked exception thrown by implementation */ protected void close(ExecutionContext ctx) throws Exception { } @@ -293,7 +293,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw /** * Registers the {@link StepExecution} for property resolution via {@link StepScope} * - * @param stepExecution + * @param stepExecution StepExecution to use when hydrating the StepScoped beans */ protected void doExecutionRegistration(StepExecution stepExecution) { StepSynchronizationManager.register(stepExecution); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/FaultTolerantStepBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/FaultTolerantStepBuilder.java index 50af6e377..ae900078e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/FaultTolerantStepBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/FaultTolerantStepBuilder.java @@ -198,7 +198,7 @@ public class FaultTolerantStepBuilder extends SimpleStepBuilder { */ @Override @SuppressWarnings("unchecked") - public SimpleStepBuilder listener(Object listener) { + public SimpleStepBuilder listener(Object listener) { super.listener(listener); Set skipListenerMethods = new HashSet(); @@ -224,7 +224,7 @@ public class FaultTolerantStepBuilder extends SimpleStepBuilder { } @SuppressWarnings("unchecked") - SimpleStepBuilder result = this; + SimpleStepBuilder result = this; return result; } @@ -548,12 +548,9 @@ public class FaultTolerantStepBuilder extends SimpleStepBuilder { types.add(ExhaustedRetryException.class); final Classifier panic = new BinaryExceptionClassifier(types, true); - classifier = new Classifier() { - @Override - public Boolean classify(Throwable classifiable) { - // Rollback if either the user's list or our own applies - return panic.classify(classifiable) || binary.classify(classifiable); - } + classifier = (Classifier) classifiable -> { + // Rollback if either the user's list or our own applies + return panic.classify(classifiable) || binary.classify(classifiable); }; } @@ -700,8 +697,9 @@ public class FaultTolerantStepBuilder extends SimpleStepBuilder { return skipPolicyWrapper; } + @SuppressWarnings("unchecked") private void addNonSkippableExceptionIfMissing(Class... cls) { - List> exceptions = new ArrayList>(); + List> exceptions = new ArrayList<>(); for (Class exceptionClass : nonSkippableExceptionClasses) { exceptions.add(exceptionClass); } @@ -713,8 +711,9 @@ public class FaultTolerantStepBuilder extends SimpleStepBuilder { nonSkippableExceptionClasses = exceptions; } + @SuppressWarnings("unchecked") private void addNonRetryableExceptionIfMissing(Class... cls) { - List> exceptions = new ArrayList>(); + List> exceptions = new ArrayList<>(); for (Class exceptionClass : nonRetryableExceptionClasses) { exceptions.add(exceptionClass); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java index faeb7d3ea..0892e9ec1 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java @@ -249,10 +249,10 @@ public class SimpleStepBuilder extends AbstractTaskletStepBuilder listener(Object listener) { super.listener(listener); - Set itemListenerMethods = new HashSet(); + Set itemListenerMethods = new HashSet<>(); itemListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), BeforeRead.class)); itemListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), AfterRead.class)); itemListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), BeforeProcess.class)); @@ -270,7 +270,7 @@ public class SimpleStepBuilder extends AbstractTaskletStepBuilder result = this; return result; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/Chunk.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/Chunk.java index e12662f65..6465652a6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/Chunk.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/Chunk.java @@ -66,7 +66,7 @@ public class Chunk implements Iterable { /** * Add the item to the chunk. - * @param item + * @param item the item to add */ public void add(W item) { items.add(item); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkOrientedTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkOrientedTasklet.java index 79edda304..c7eb3102e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkOrientedTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkOrientedTasklet.java @@ -54,7 +54,7 @@ public class ChunkOrientedTasklet implements Tasklet { * readers. Main (or only) use case for setting this flag to false is a * transactional JMS item reader. * - * @param buffering + * @param buffering indicator */ public void setBuffering(boolean buffering) { this.buffering = buffering; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java index 906af7753..d19abbce6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java @@ -49,7 +49,7 @@ public class CallableTaskletAdapter implements Tasklet, InitializingBean { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(callable); + Assert.notNull(callable, "A Callable is required"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapper.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapper.java index 0f4dca290..bbc02b38b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapper.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapper.java @@ -50,7 +50,7 @@ public class ConfigurableSystemProcessExitCodeMapper implements SystemProcessExi * {@link org.springframework.batch.core.ExitStatus} values. */ public void setMappings(Map mappings) { - Assert.notNull(mappings.get(ELSE_KEY)); + Assert.notNull(mappings.get(ELSE_KEY), "Missing value for " + ELSE_KEY); this.mappings = mappings; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java index 4eb885103..1af05283a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java @@ -15,11 +15,10 @@ */ package org.springframework.batch.core.configuration.xml; -import static org.junit.Assert.fail; - import java.util.ArrayList; import org.junit.Before; + import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParametersBuilder; @@ -31,6 +30,8 @@ import org.springframework.batch.core.repository.JobRestartException; import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; +import static org.junit.Assert.fail; + /** * @author Dan Garrette * @since 2.0 @@ -63,11 +64,6 @@ public abstract class AbstractJobParserTests { return jobRepository.createJobExecution(job.getName(), new JobParametersBuilder().addLong("key1", 1L).toJobParameters()); } - /** - * @param jobExecution - * @param stepName - * @return the StepExecution corresponding to the specified step - */ protected StepExecution getStepExecution(JobExecution jobExecution, String stepName) { for (StepExecution stepExecution : jobExecution.getStepExecutions()) { if (stepExecution.getStepName().equals(stepName)) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java index 0e9d668af..4de84419b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java @@ -15,18 +15,13 @@ */ package org.springframework.batch.core.configuration.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Map; import org.junit.Test; + import org.springframework.batch.core.Step; import org.springframework.batch.core.step.item.SimpleChunkProcessor; import org.springframework.batch.core.step.skip.SkipPolicy; @@ -50,6 +45,12 @@ import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.StringUtils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author Dan Garrette * @author Dave Syer @@ -338,7 +339,7 @@ public class ChunkElementParserTests { /** * @param object the target object * @param path the path to the required field - * @return + * @return The field */ private Object getNestedPath(Object object, String path) { while (StringUtils.hasText(path)) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/AbstractJsrTestCase.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/AbstractJsrTestCase.java index 50c8d5b47..06fddea38 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/AbstractJsrTestCase.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/AbstractJsrTestCase.java @@ -43,9 +43,9 @@ public abstract class AbstractJsrTestCase { * reach one of those statuses within the given timeout, a {@link java.util.concurrent.TimeoutException} is * thrown. * - * @param jobName - * @param properties - * @param timeout + * @param jobName Name of the job to run + * @param properties Properties to pass the job + * @param timeout length of time to wait for a job to finish * @return the {@link javax.batch.runtime.JobExecution} for the final state of the job * @throws java.util.concurrent.TimeoutException if the timeout occurs */ @@ -78,9 +78,9 @@ public abstract class AbstractJsrTestCase { * reach one of those statuses within the given timeout, a {@link java.util.concurrent.TimeoutException} is * thrown. * - * @param executionId - * @param properties - * @param timeout + * @param executionId The execution id to restart + * @param properties The Properties to pass to the new run + * @param timeout The length of time to wait for the job to run * @return the {@link JobExecution} for the final state of the job * @throws java.util.concurrent.TimeoutException if the timeout occurs */ diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java index e3a2f5d5c..8e9783e13 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java @@ -15,12 +15,9 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import static org.junit.Assert.assertEquals; - import java.io.Serializable; import java.util.List; import java.util.Properties; - import javax.batch.api.BatchProperty; import javax.batch.api.Batchlet; import javax.batch.api.Decider; @@ -35,12 +32,15 @@ import javax.batch.runtime.context.JobContext; import javax.inject.Inject; import org.junit.Test; + import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.jsr.AbstractJsrTestCase; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; +import static org.junit.Assert.assertEquals; + /** *

* Configuration test for parsing various <properties /> elements defined by JSR-352. @@ -78,30 +78,30 @@ public class JobPropertyTests extends AbstractJsrTestCase { @Override public void open(Serializable serializable) throws Exception { - org.springframework.util.Assert.notNull(stepContext); - org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName1")); - org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName2")); - org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName1").equals("step1PropertyValue1")); - org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName2").equals("step1PropertyValue2")); - org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null); - org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null); - org.springframework.util.Assert.isTrue("readerPropertyValue1".equals(readerPropertyName1)); - org.springframework.util.Assert.isTrue("readerPropertyValue2".equals(readerPropertyName2)); - org.springframework.util.Assert.isTrue("annotationNamedReaderPropertyValue".equals(annotationNamedProperty)); - org.springframework.util.Assert.isNull(notDefinedProperty); - org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty); - org.springframework.util.Assert.isNull(batchAnnotatedOnlyField); - org.springframework.util.Assert.notNull(injectAnnotatedOnlyField); - org.springframework.util.Assert.isTrue("job1".equals(injectAnnotatedOnlyField.getJobName())); - org.springframework.util.Assert.isNull(readerPropertyName3); + org.springframework.util.Assert.notNull(stepContext, "stepContext is not null"); + org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName1"), "step2PropertyName1 is not null"); + org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName2"), "step2PropertyName2 is not null"); + org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName1").equals("step1PropertyValue1"), "The value of step2PropertyName1 does not equal step2PropertyName1"); + org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName2").equals("step1PropertyValue2"), "The value of step2PropertyName2 does not equal step2PropertyName2"); + org.springframework.util.Assert.isNull(stepContext.getProperties().get("jobPropertyName1"), "jobPropertyName1 is not null"); + org.springframework.util.Assert.isNull(stepContext.getProperties().get("jobPropertyName2") == null, "jobPropertyName2 is not null"); + org.springframework.util.Assert.isTrue("readerPropertyValue1".equals(readerPropertyName1), "The value of readerPropertyValue1 does not equal readerPropertyValue1"); + org.springframework.util.Assert.isTrue("readerPropertyValue2".equals(readerPropertyName2), "The value of readerPropertyValue2 does not equal readerPropertyValue2"); + org.springframework.util.Assert.isTrue("annotationNamedReaderPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedReaderPropertyValue does not equal annotationNamedReaderPropertyValue"); + org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null"); + org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null"); + org.springframework.util.Assert.isNull(batchAnnotatedOnlyField, "batchAnnotatedOnlyField is not null"); + org.springframework.util.Assert.notNull(injectAnnotatedOnlyField, "injectAnnotatedOnlyField is not null"); + org.springframework.util.Assert.isTrue("job1".equals(injectAnnotatedOnlyField.getJobName()), "injectAnnotatedOnlyField does not equal job1"); + org.springframework.util.Assert.isNull(readerPropertyName3, "readerPropertyName3 is not null"); Properties jobProperties = injectAnnotatedOnlyField.getProperties(); - org.springframework.util.Assert.isTrue(jobProperties.size() == 5); - org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName1").equals("jobPropertyValue1")); - org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName2").equals("jobPropertyValue2")); - org.springframework.util.Assert.isTrue(jobProperties.get("step2name").equals("step2")); - org.springframework.util.Assert.isTrue(jobProperties.get("filestem").equals("postings")); - org.springframework.util.Assert.isTrue(jobProperties.get("x").equals("xVal")); + org.springframework.util.Assert.isTrue(jobProperties.size() == 5, "jobProperties has the wrong number of values. Expected 5, got " + jobProperties.size()); + org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName1").equals("jobPropertyValue1"), "The value of jobPropertyName1 does not equal jobPropertyName1"); + org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName2").equals("jobPropertyValue2"), "The value of jobPropertyName2 does not equal jobPropertyName2"); + org.springframework.util.Assert.isTrue(jobProperties.get("step2name").equals("step2"), "The value of step2name does note equal step2"); + org.springframework.util.Assert.isTrue(jobProperties.get("filestem").equals("postings"), "The value of filestem does not equal postings"); + org.springframework.util.Assert.isTrue(jobProperties.get("x").equals("xVal"), "The value of x does not equal xVal"); } @Override @@ -133,11 +133,11 @@ public class JobPropertyTests extends AbstractJsrTestCase { @Override public Object processItem(Object o) throws Exception { - org.springframework.util.Assert.isTrue("processorPropertyValue1".equals(processorPropertyName1)); - org.springframework.util.Assert.isTrue("processorPropertyValue2".equals(processorPropertyName2)); - org.springframework.util.Assert.isTrue("annotationNamedProcessorPropertyValue".equals(annotationNamedProperty)); - org.springframework.util.Assert.isNull(notDefinedProperty); - org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty); + org.springframework.util.Assert.isTrue("processorPropertyValue1".equals(processorPropertyName1), "The value of processorPropertyValue1 does not equal processorPropertyValue1"); + org.springframework.util.Assert.isTrue("processorPropertyValue2".equals(processorPropertyName2), "The value of processorPropertyValue2 does not equal processorPropertyValue2"); + org.springframework.util.Assert.isTrue("annotationNamedProcessorPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedProcessorPropertyValue does not equal annotationNamedProcessorPropertyValue"); + org.springframework.util.Assert.isNull(notDefinedProperty, "The notDefinedProperty is not null"); + org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "The notDefinedNamedProperty is not null"); return o; } @@ -152,11 +152,11 @@ public class JobPropertyTests extends AbstractJsrTestCase { @Override public void open(Serializable serializable) throws Exception { - org.springframework.util.Assert.isTrue("writerPropertyValue1".equals(writerPropertyName1)); - org.springframework.util.Assert.isTrue("writerPropertyValue2".equals(writerPropertyName2)); - org.springframework.util.Assert.isTrue("annotationNamedWriterPropertyValue".equals(annotationNamedProperty)); - org.springframework.util.Assert.isNull(notDefinedProperty); - org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty); + org.springframework.util.Assert.isTrue("writerPropertyValue1".equals(writerPropertyName1), "The value of writerPropertyValue1 does not equal writerPropertyValue1"); + org.springframework.util.Assert.isTrue("writerPropertyValue2".equals(writerPropertyName2), "The value of writerPropertyValue2 does not equal writerPropertyValue2"); + org.springframework.util.Assert.isTrue("annotationNamedWriterPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedWriterPropertyValue does not equal annotationNamedWriterPropertyValue"); + org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null"); + org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null"); } @Override @@ -188,11 +188,11 @@ public class JobPropertyTests extends AbstractJsrTestCase { @Override public void beginCheckpoint() throws Exception { - org.springframework.util.Assert.isTrue("algorithmPropertyValue1".equals(algorithmPropertyName1)); - org.springframework.util.Assert.isTrue("algorithmPropertyValue2".equals(algorithmPropertyName2)); - org.springframework.util.Assert.isTrue("annotationNamedAlgorithmPropertyValue".equals(annotationNamedProperty)); - org.springframework.util.Assert.isNull(notDefinedProperty); - org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty); + org.springframework.util.Assert.isTrue("algorithmPropertyValue1".equals(algorithmPropertyName1), "The value of algorithmPropertyValue1 does not equal algorithmPropertyValue1"); + org.springframework.util.Assert.isTrue("algorithmPropertyValue2".equals(algorithmPropertyName2), "The value of algorithmPropertyValue2 does not equal algorithmPropertyValue2"); + org.springframework.util.Assert.isTrue("annotationNamedAlgorithmPropertyValue".equals(annotationNamedProperty), "The annotationNamedAlgorithmPropertyValue does not equal annotationNamedAlgorithmPropertyValue"); + org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null"); + org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null"); } @Override @@ -214,11 +214,11 @@ public class JobPropertyTests extends AbstractJsrTestCase { @Override public String decide(javax.batch.runtime.StepExecution[] executions) throws Exception { - org.springframework.util.Assert.isTrue("deciderPropertyValue1".equals(deciderPropertyName1)); - org.springframework.util.Assert.isTrue("deciderPropertyValue2".equals(deciderPropertyName2)); - org.springframework.util.Assert.isTrue("annotationNamedDeciderPropertyValue".equals(annotationNamedProperty)); - org.springframework.util.Assert.isNull(notDefinedProperty); - org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty); + org.springframework.util.Assert.isTrue("deciderPropertyValue1".equals(deciderPropertyName1), "The value of deciderPropertyValue1 does not equal deciderPropertyValue1"); + org.springframework.util.Assert.isTrue("deciderPropertyValue2".equals(deciderPropertyName2), "The value of deciderPropertyValue2 does not equal deciderPropertyValue2"); + org.springframework.util.Assert.isTrue("annotationNamedDeciderPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedDeciderPropertyValue does not equal annotationNamedDeciderPropertyValue"); + org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null"); + org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null"); return "step2"; } @@ -233,11 +233,11 @@ public class JobPropertyTests extends AbstractJsrTestCase { @Override public void beforeStep() throws Exception { - org.springframework.util.Assert.isTrue("stepListenerPropertyValue1".equals(stepListenerPropertyName1)); - org.springframework.util.Assert.isTrue("stepListenerPropertyValue2".equals(stepListenerPropertyName2)); - org.springframework.util.Assert.isTrue("annotationNamedStepListenerPropertyValue".equals(annotationNamedProperty)); - org.springframework.util.Assert.isNull(notDefinedProperty); - org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty); + org.springframework.util.Assert.isTrue("stepListenerPropertyValue1".equals(stepListenerPropertyName1), "The value of stepListenerPropertyValue1 does not equal stepListenerPropertyValue1"); + org.springframework.util.Assert.isTrue("stepListenerPropertyValue2".equals(stepListenerPropertyName2), "The value of stepListenerPropertyValue2 does not equal stepListenerPropertyValue2"); + org.springframework.util.Assert.isTrue("annotationNamedStepListenerPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedStepListenerPropertyValue does note equal annotationNamedStepListenerPropertyValue"); + org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null"); + org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null"); } @Override @@ -258,22 +258,22 @@ public class JobPropertyTests extends AbstractJsrTestCase { @Override public String process() throws Exception { - org.springframework.util.Assert.notNull(stepContext); - org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName1")); - org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName2")); - org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName1").equals("step2PropertyValue1")); - org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName2").equals("step2PropertyValue2")); - org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null); - org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null); + org.springframework.util.Assert.notNull(stepContext, "StepContext is not null"); + org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName1"), "The value of step1PropertyName1 is not null"); + org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName2"), "The value of step1PropertyName2 is not null"); + org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName1").equals("step2PropertyValue1"), "The value of step2PropertyName1 does not equal step2PropertyName1"); + org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName2").equals("step2PropertyValue2"), "The value of step2PropertyName2 does not equal step2PropertyName2"); + org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null, "jobPropertyName1 is not null"); + org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null, "jobPropertyName2 is not null"); - org.springframework.util.Assert.isTrue("batchletPropertyValue1".equals(batchletPropertyName1)); - org.springframework.util.Assert.isTrue("batchletPropertyValue2".equals(batchletPropertyName2)); - org.springframework.util.Assert.isTrue("annotationNamedBatchletPropertyValue".equals(annotationNamedProperty)); - org.springframework.util.Assert.isTrue("postings.txt".equals(infile)); - org.springframework.util.Assert.isTrue("xVal".equals(y)); - org.springframework.util.Assert.isNull(notDefinedProperty); - org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty); - org.springframework.util.Assert.isNull(x); + org.springframework.util.Assert.isTrue("batchletPropertyValue1".equals(batchletPropertyName1), "batchletPropertyValue1 does not equal batchletPropertyValue1"); + org.springframework.util.Assert.isTrue("batchletPropertyValue2".equals(batchletPropertyName2), "batchletPropertyValue2 does not equal batchletPropertyValue2"); + org.springframework.util.Assert.isTrue("annotationNamedBatchletPropertyValue".equals(annotationNamedProperty), "annotationNamedBatchletPropertyValue does not equal annotationNamedBatchletPropertyValue"); + org.springframework.util.Assert.isTrue("postings.txt".equals(infile), "infile does not equal postings.txt"); + org.springframework.util.Assert.isTrue("xVal".equals(y), "y does not equal xVal"); + org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null"); + org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null"); + org.springframework.util.Assert.isNull(x, "x is not null"); return null; } @@ -290,7 +290,7 @@ public class JobPropertyTests extends AbstractJsrTestCase { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { - org.springframework.util.Assert.isTrue("p1val".equals(p1)); + org.springframework.util.Assert.isTrue("p1val".equals(p1), "Expected p1val, got " + p1); return RepeatStatus.FINISHED; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/PartitionParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/PartitionParserTests.java index 0833a46a1..93adb107f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/PartitionParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/PartitionParserTests.java @@ -15,11 +15,16 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import org.junit.Before; -import org.junit.Test; -import org.springframework.batch.core.jsr.AbstractJsrTestCase; -import org.springframework.util.Assert; - +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.Vector; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.batch.api.BatchProperty; import javax.batch.api.Batchlet; import javax.batch.api.chunk.AbstractItemReader; @@ -31,16 +36,12 @@ import javax.batch.runtime.JobExecution; import javax.batch.runtime.context.JobContext; import javax.batch.runtime.context.StepContext; import javax.inject.Inject; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.Vector; -import java.util.regex.Matcher; -import java.util.regex.Pattern; + +import org.junit.Before; +import org.junit.Test; + +import org.springframework.batch.core.jsr.AbstractJsrTestCase; +import org.springframework.util.Assert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -221,14 +222,14 @@ public class PartitionParserTests extends AbstractJsrTestCase { public void analyzeCollectorData(Serializable data) throws Exception { name = artifactName; - Assert.isTrue(data.equals("c")); + Assert.isTrue(data.equals("c"), "Expected c but was " + data); jobContext.setExitStatus(jobContext.getExitStatus() + data + "a"); } @Override public void analyzeStatus(BatchStatus batchStatus, String exitStatus) throws Exception { - Assert.isTrue(batchStatus.equals(BatchStatus.COMPLETED)); + Assert.isTrue(batchStatus.equals(BatchStatus.COMPLETED), String.format("expected %s but received %s", BatchStatus.COMPLETED, batchStatus)); jobContext.setExitStatus(jobContext.getExitStatus() + "AS"); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/RetryListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/RetryListenerTests.java index 9ad9fc772..8b0a66bb7 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/RetryListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/RetryListenerTests.java @@ -124,7 +124,7 @@ public class RetryListenerTests { String currentItem = (String) item; - Assert.isTrue("three".equals(currentItem)); + Assert.isTrue("three".equals(currentItem), "currentItem was expected to be three but was not " + currentItem); Assert.isInstanceOf(IllegalArgumentException.class, ex); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ThreadLocalClassloaderBeanPostProcessorTestsBatchlet.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ThreadLocalClassloaderBeanPostProcessorTestsBatchlet.java index 3a2dc092b..b0424c4d7 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ThreadLocalClassloaderBeanPostProcessorTestsBatchlet.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ThreadLocalClassloaderBeanPostProcessorTestsBatchlet.java @@ -37,8 +37,9 @@ public class ThreadLocalClassloaderBeanPostProcessorTestsBatchlet implements Bat @Override public String process() throws Exception { Assert.isTrue("someParameter".equals(jobParam1), jobParam1 + " does not equal someParamter"); - Assert.isTrue("threadLocalClassloaderBeanPostProcessorTestsJob".equals(jobContext.getJobName())); - Assert.isTrue("step1".equals(stepContext.getStepName())); + Assert.isTrue("threadLocalClassloaderBeanPostProcessorTestsJob".equals(jobContext.getJobName()), + "jobName does not equal threadLocalClassloaderBeanPostProcessorTestsJob"); + Assert.isTrue("step1".equals(stepContext.getStepName()), "stepName does not equal step1"); return null; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/DecisionStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/DecisionStepTests.java index 22af01a00..85da23740 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/DecisionStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/DecisionStepTests.java @@ -140,8 +140,8 @@ public class DecisionStepTests extends AbstractJsrTestCase { @Override public String decide(StepExecution[] executions) throws Exception { - Assert.isTrue(executions.length == 1); - Assert.isTrue(executions[0].getStepName().equals("step1")); + Assert.isTrue(executions.length == 1, "Invalid array length"); + Assert.isTrue(executions[0].getStepName().equals("step1"), "Incorrect step name"); if(runs == 0) { runs++; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java index 5c2997e51..94554c6d3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java @@ -15,15 +15,16 @@ */ package org.springframework.batch.core.listener; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - import org.junit.Test; + import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; import org.springframework.util.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + /** * Tests for {@link ExecutionContextPromotionListener}. */ @@ -57,8 +58,8 @@ public class ExecutionContextPromotionListenerTests { StepExecution stepExecution = jobExecution.createStepExecution("step1"); stepExecution.setExitStatus(ExitStatus.COMPLETED); - Assert.state(jobExecution.getExecutionContext().isEmpty()); - Assert.state(stepExecution.getExecutionContext().isEmpty()); + Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty"); + Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty"); stepExecution.getExecutionContext().putString(key, value); stepExecution.getExecutionContext().putString(key2, value2); @@ -87,8 +88,8 @@ public class ExecutionContextPromotionListenerTests { StepExecution stepExecution = jobExecution.createStepExecution("step1"); stepExecution.setExitStatus(new ExitStatus(status)); - Assert.state(jobExecution.getExecutionContext().isEmpty()); - Assert.state(stepExecution.getExecutionContext().isEmpty()); + Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty"); + Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty"); stepExecution.getExecutionContext().putString(key, value); stepExecution.getExecutionContext().putString(key2, value2); @@ -117,8 +118,8 @@ public class ExecutionContextPromotionListenerTests { StepExecution stepExecution = jobExecution.createStepExecution("step1"); stepExecution.setExitStatus(new ExitStatus(status2)); - Assert.state(jobExecution.getExecutionContext().isEmpty()); - Assert.state(stepExecution.getExecutionContext().isEmpty()); + Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty"); + Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty"); stepExecution.getExecutionContext().putString(key, value); stepExecution.getExecutionContext().putString(key2, value2); @@ -147,8 +148,8 @@ public class ExecutionContextPromotionListenerTests { StepExecution stepExecution = jobExecution.createStepExecution("step1"); stepExecution.setExitStatus(new ExitStatus(status)); - Assert.state(jobExecution.getExecutionContext().isEmpty()); - Assert.state(stepExecution.getExecutionContext().isEmpty()); + Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty"); + Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty"); stepExecution.getExecutionContext().putString(key, value); stepExecution.getExecutionContext().putString(key2, value2); @@ -176,8 +177,8 @@ public class ExecutionContextPromotionListenerTests { StepExecution stepExecution = jobExecution.createStepExecution("step1"); stepExecution.setExitStatus(ExitStatus.COMPLETED); - Assert.state(jobExecution.getExecutionContext().isEmpty()); - Assert.state(stepExecution.getExecutionContext().isEmpty()); + Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty"); + Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty"); stepExecution.getExecutionContext().putString(key, value); @@ -203,8 +204,8 @@ public class ExecutionContextPromotionListenerTests { StepExecution stepExecution = jobExecution.createStepExecution("step1"); stepExecution.setExitStatus(ExitStatus.COMPLETED); - Assert.state(jobExecution.getExecutionContext().isEmpty()); - Assert.state(stepExecution.getExecutionContext().isEmpty()); + Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty"); + Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty"); jobExecution.getExecutionContext().putString(key, value); @@ -231,8 +232,8 @@ public class ExecutionContextPromotionListenerTests { StepExecution stepExecution = jobExecution.createStepExecution("step1"); stepExecution.setExitStatus(ExitStatus.COMPLETED); - Assert.state(jobExecution.getExecutionContext().isEmpty()); - Assert.state(stepExecution.getExecutionContext().isEmpty()); + Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty"); + Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty"); stepExecution.getExecutionContext().putString(key, value); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/StepListenerFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/StepListenerFactoryBeanTests.java index 79eea54c6..44bb06ddb 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/StepListenerFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/StepListenerFactoryBeanTests.java @@ -15,23 +15,17 @@ */ package org.springframework.batch.core.listener; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER_STEP; -import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER_WRITE; - import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.sql.DataSource; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.junit.Before; import org.junit.Test; + import org.springframework.aop.framework.ProxyFactory; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.ExitStatus; @@ -63,6 +57,12 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.core.Ordered; import org.springframework.util.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER_STEP; +import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER_WRITE; + /** * @author Lucas Ward * @@ -380,7 +380,7 @@ public class StepListenerFactoryBeanTests { @Override @AfterStep public ExitStatus afterStep(StepExecution stepExecution) { - Assert.notNull(stepExecution); + Assert.notNull(stepExecution, "A stepExecution is required"); callcount++; return null; } @@ -399,7 +399,7 @@ public class StepListenerFactoryBeanTests { @Override public ExitStatus afterStep(StepExecution stepExecution) { - Assert.notNull(stepExecution); + Assert.notNull(stepExecution, "A stepExecution is required"); callcount++; return null; } @@ -489,7 +489,7 @@ public class StepListenerFactoryBeanTests { @AfterRead public void afterReadMethod(Object item) { - Assert.notNull(item); + Assert.notNull(item, "An item is required"); afterReadCalled = true; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java index 2aee364ba..e5658dff9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java @@ -15,11 +15,6 @@ */ package org.springframework.batch.core.repository.dao; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -28,6 +23,7 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; + import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; @@ -36,7 +32,12 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public abstract class AbstractJobExecutionDaoTests { @@ -307,13 +308,13 @@ public abstract class AbstractJobExecutionDaoTests { dao.saveJobExecution(exec1); JobExecution exec2 = new JobExecution(jobInstance, jobParameters); - Assert.state(exec1.getId() != null); + assertTrue(exec1.getId() != null); exec2.setId(exec1.getId()); exec2.setStatus(BatchStatus.STARTED); exec2.setVersion(7); - Assert.state(exec1.getVersion() != exec2.getVersion()); - Assert.state(exec1.getStatus() != exec2.getStatus()); + assertTrue(exec1.getVersion() != exec2.getVersion()); + assertTrue(exec1.getStatus() != exec2.getStatus()); dao.synchronizeStatus(exec2); @@ -334,13 +335,13 @@ public abstract class AbstractJobExecutionDaoTests { dao.saveJobExecution(exec1); JobExecution exec2 = new JobExecution(jobInstance, jobParameters); - Assert.state(exec1.getId() != null); + assertTrue(exec1.getId() != null); exec2.setId(exec1.getId()); exec2.setStatus(BatchStatus.UNKNOWN); exec2.setVersion(7); - Assert.state(exec1.getVersion() != exec2.getVersion()); - Assert.state(exec1.getStatus().isLessThan(exec2.getStatus())); + assertTrue(exec1.getVersion() != exec2.getVersion()); + assertTrue(exec1.getStatus().isLessThan(exec2.getStatus())); dao.synchronizeStatus(exec2); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/AlmostStatefulRetryChunkTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/AlmostStatefulRetryChunkTests.java index af392af9c..4fbade723 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/AlmostStatefulRetryChunkTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/AlmostStatefulRetryChunkTests.java @@ -15,10 +15,6 @@ */ package org.springframework.batch.core.step.item; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -30,6 +26,10 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Dave Syer * @@ -81,8 +81,7 @@ public class AlmostStatefulRetryChunkTests { } /** - * @param chunk - * @throws Exception + * @param chunk Chunk to retry */ private void statefulRetry(Chunk chunk) throws Exception { if (retryAttempts <= retryLimit) { @@ -113,8 +112,7 @@ public class AlmostStatefulRetryChunkTests { } /** - * @param chunk - * @throws Exception + * @param chunk Chunk to recover */ private void recover(Chunk chunk) throws Exception { for (Chunk.ChunkIterator iterator = chunk.iterator(); iterator.hasNext();) { @@ -129,8 +127,7 @@ public class AlmostStatefulRetryChunkTests { } /** - * @param items - * @throws Exception + * @param items items to write */ private void doWrite(List items) throws Exception { if (items.contains("fail")) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java index 1d0288d5b..9685597f2 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java @@ -224,7 +224,7 @@ public class SystemCommandTaskletIntegrationTests { @Test public void testWorkingDirectory() throws Exception { File notExistingFile = new File("not-existing-path"); - Assert.state(!notExistingFile.exists()); + Assert.state(!notExistingFile.exists(), "not-existing-path does actually exist"); try { tasklet.setWorkingDirectory(notExistingFile.getCanonicalPath()); @@ -235,8 +235,8 @@ public class SystemCommandTaskletIntegrationTests { } File notDirectory = File.createTempFile(this.getClass().getName(), null); - Assert.state(notDirectory.exists()); - Assert.state(!notDirectory.isDirectory()); + Assert.state(notDirectory.exists(), "The file does not exist"); + Assert.state(!notDirectory.isDirectory(), "The file is actually a directory"); try { tasklet.setWorkingDirectory(notDirectory.getCanonicalPath()); @@ -247,8 +247,8 @@ public class SystemCommandTaskletIntegrationTests { } File directory = notDirectory.getParentFile(); - Assert.state(directory.exists()); - Assert.state(directory.isDirectory()); + Assert.state(directory.exists(), "The directory does not exist"); + Assert.state(directory.isDirectory(), "The directory is not a directory"); // no error expected now tasklet.setWorkingDirectory(directory.getCanonicalPath()); diff --git a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index 9c3303476..42b15e476 100644 --- a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -16,9 +16,14 @@ package test.jdbc.datasource; +import java.io.IOException; +import java.util.List; +import javax.sql.DataSource; + import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -33,10 +38,6 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; -import javax.sql.DataSource; -import java.io.IOException; -import java.util.List; - /** * Wrapper for a {@link DataSource} that can run scripts on start up and shut * down. Us as a bean definition

@@ -75,7 +76,7 @@ public class DataSourceInitializer implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource); + Assert.notNull(dataSource, "A DataSource is required"); initialize(); } diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java index c6e61bcb9..38608207f 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java @@ -16,16 +16,8 @@ package org.springframework.batch.container.jms; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; - import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.Message; @@ -35,11 +27,19 @@ import javax.jms.Session; import org.aopalliance.aop.Advice; import org.junit.Test; + import org.springframework.batch.repeat.interceptor.RepeatOperationsInterceptor; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; import org.springframework.util.ReflectionUtils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class BatchMessageListenerContainerTests { BatchMessageListenerContainer container; @@ -186,13 +186,12 @@ public class BatchMessageListenerContainerTests { } private boolean doExecute(Session session, MessageConsumer consumer) throws IllegalAccessException { - Method method = ReflectionUtils.findMethod(container.getClass(), "receiveAndExecute", new Class[] { - Object.class, Session.class, MessageConsumer.class }); + Method method = ReflectionUtils.findMethod(container.getClass(), "receiveAndExecute", Object.class, Session.class, MessageConsumer.class); method.setAccessible(true); boolean received; try { // A null invoker is not normal, but we don't care about the invoker for a unit test - received = ((Boolean) method.invoke(container, new Object[] { null, session, consumer })).booleanValue(); + received = (Boolean) method.invoke(container, null, session, consumer); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java index 115bdc8ec..0a192cd7d 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java @@ -16,13 +16,8 @@ package org.springframework.batch.repeat.jms; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.List; - import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Session; @@ -45,6 +40,10 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.ClassUtils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") @DirtiesContext @@ -190,9 +189,9 @@ public class AsynchronousTests { } /** - * @param list - * @param timeout - * @throws InterruptedException + * @param list resource to monitor + * @param timeout how long to monitor for + * @throws InterruptedException If interrupted while waiting */ private void waitFor(List list, int size, int timeout) throws InterruptedException { int count = 0; diff --git a/spring-batch-infrastructure-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-infrastructure-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index e7130e1ee..b8c1cb473 100644 --- a/spring-batch-infrastructure-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-infrastructure-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -79,7 +79,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource); + Assert.notNull(dataSource, "DataSource is required"); logger.info("Initializing with scripts: " + Arrays.asList(initScripts)); if (!initialized && initialize) { try { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java index dc01d86a5..22308a974 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java @@ -107,10 +107,7 @@ public abstract class AbstractMethodInvokingDelegator implements Initializing try { invoker.prepare(); } - catch (ClassNotFoundException e) { - throw new DynamicMethodInvocationException(e); - } - catch (NoSuchMethodException e) { + catch (ClassNotFoundException | NoSuchMethodException e) { throw new DynamicMethodInvocationException(e); } @@ -132,8 +129,8 @@ public abstract class AbstractMethodInvokingDelegator implements Initializing @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(targetObject); - Assert.hasLength(targetMethod); + Assert.notNull(targetObject, "targetObject must not be null"); + Assert.hasLength(targetMethod, "targetMethod must not be empty"); Assert.state(targetClassDeclaresTargetMethod(), "target class must declare a method with matching name and parameter types"); } @@ -148,7 +145,7 @@ public abstract class AbstractMethodInvokingDelegator implements Initializing Method[] memberMethods = invoker.getTargetClass().getMethods(); Method[] declaredMethods = invoker.getTargetClass().getDeclaredMethods(); - List allMethods = new ArrayList(); + List allMethods = new ArrayList<>(); allMethods.addAll(Arrays.asList(memberMethods)); allMethods.addAll(Arrays.asList(declaredMethods)); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java index f7d997983..5b610b62f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java @@ -62,7 +62,7 @@ ItemWriter { @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notEmpty(fieldsUsedAsTargetMethodArguments); + Assert.notEmpty(fieldsUsedAsTargetMethodArguments, "fieldsUsedAsTargetMethodArguments must not be empty"); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java index 23d100c00..3208602e7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java @@ -16,7 +16,15 @@ package org.springframework.batch.item.data; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import com.mongodb.util.JSON; + import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.beans.factory.InitializingBean; @@ -30,13 +38,6 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - /** *

* Restartable {@link ItemReader} that reads documents from MongoDB @@ -117,7 +118,7 @@ public class MongoItemReader extends AbstractPaginatedDataItemReader imple * {@link List} of values to be substituted in for each of the * parameters in the query. * - * @param parameterValues + * @param parameterValues values */ public void setParameterValues(List parameterValues) { this.parameterValues = parameterValues; @@ -163,11 +164,11 @@ public class MongoItemReader extends AbstractPaginatedDataItemReader imple @SuppressWarnings("unchecked") protected Iterator doPageRead() { - Pageable pageRequest = new PageRequest(page, pageSize, sort); + Pageable pageRequest = PageRequest.of(page, pageSize, sort); String populatedQuery = replacePlaceholders(query, parameterValues); - Query mongoQuery = null; + Query mongoQuery; if(StringUtils.hasText(fields)) { mongoQuery = new BasicQuery(populatedQuery, fields); @@ -222,12 +223,12 @@ public class MongoItemReader extends AbstractPaginatedDataItemReader imple } private Sort convertToSort(Map sorts) { - List sortValues = new ArrayList(); + List sortValues = new ArrayList<>(); for (Map.Entry curSort : sorts.entrySet()) { sortValues.add(new Sort.Order(curSort.getValue(), curSort.getKey())); } - return new Sort(sortValues); + return Sort.by(sortValues); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemReader.java index 6779a2bd8..e7797e7ca 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemReader.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Iterator; import org.neo4j.ogm.session.Session; -import org.neo4j.ogm.session.SessionFactory; /** *

@@ -29,19 +28,16 @@ import org.neo4j.ogm.session.SessionFactory; * * @author Michael Minella */ -public class Neo4jItemReader extends AbstractNeo4jItemReader { +public class Neo4jItemReader extends AbstractNeo4jItemReader { + @SuppressWarnings("unchecked") @Override protected Iterator doPageRead() { - SessionFactory factory = getSessionFactory(); + Session session = getSessionFactory().openSession(); - Iterable queryResults; - - Session session = factory.openSession(); - - queryResults = session.query(getTargetType(), - generateLimitCypherQuery(), - getParameterValues()); + Iterable queryResults = session.query(getTargetType(), + generateLimitCypherQuery(), + getParameterValues()); if(queryResults != null) { return queryResults.iterator(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java index ea59a4b29..950fe2186 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java @@ -127,7 +127,7 @@ public class RepositoryItemReader extends AbstractItemCountingItemStreamItemR * Specifies what method on the repository to call. This method must take * {@link org.springframework.data.domain.Pageable} as the last argument. * - * @param methodName + * @param methodName name of the method to invoke */ public void setMethodName(String methodName) { this.methodName = methodName; @@ -187,15 +187,16 @@ public class RepositoryItemReader extends AbstractItemCountingItemStreamItemR * Available for overriding as needed. * * @return the list of items that make up the page - * @throws Exception + * @throws Exception Based on what the underlying method throws or related to the + * calling of the method */ @SuppressWarnings("unchecked") protected List doPageRead() throws Exception { - Pageable pageRequest = new PageRequest(page, pageSize, sort); + Pageable pageRequest = PageRequest.of(page, pageSize, sort); MethodInvoker invoker = createMethodInvoker(repository, methodName); - List parameters = new ArrayList(); + List parameters = new ArrayList<>(); if(arguments != null && arguments.size() > 0) { parameters.addAll(arguments); @@ -224,23 +225,20 @@ public class RepositoryItemReader extends AbstractItemCountingItemStreamItemR } private Sort convertToSort(Map sorts) { - List sortValues = new ArrayList(); + List sortValues = new ArrayList<>(); for (Map.Entry curSort : sorts.entrySet()) { sortValues.add(new Sort.Order(curSort.getValue(), curSort.getKey())); } - return new Sort(sortValues); + return Sort.by(sortValues); } private Object doInvoke(MethodInvoker invoker) throws Exception{ try { invoker.prepare(); } - catch (ClassNotFoundException e) { - throw new DynamicMethodInvocationException(e); - } - catch (NoSuchMethodException e) { + catch (ClassNotFoundException | NoSuchMethodException e) { throw new DynamicMethodInvocationException(e); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractCursorItemReader.java index e0660fd25..ddbb0f81b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractCursorItemReader.java @@ -246,7 +246,7 @@ implements InitializingBean { /** * Moves the cursor in the ResultSet to the position specified by the row * parameter by traversing the ResultSet. - * @param row + * @param row The index of the row to move to */ private void moveCursorToRow(int row) { try { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxy.java index 82e8a7ded..bdfab9015 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxy.java @@ -143,10 +143,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi * @return true or false */ public boolean isCloseSuppressionActive(Connection connection) { - if (connection == null) { - return false; - } - return connection.equals(closeSuppressedConnection); + return connection != null && connection.equals(closeSuppressedConnection); } /** @@ -240,6 +237,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi * @param target the original Connection to wrap * @return the wrapped Connection */ + @SuppressWarnings("rawtypes") protected Connection getCloseSuppressingConnectionProxy(Connection target) { return (Connection) Proxy.newProxyInstance(ConnectionProxy.class.getClassLoader(), new Class[] { ConnectionProxy.class }, new CloseSuppressingInvocationHandler(target, this)); @@ -265,29 +263,27 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... - if (method.getName().equals("equals")) { - // Only consider equal when proxies are identical. - return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE); - } - else if (method.getName().equals("hashCode")) { - // Use hashCode of Connection proxy. - return new Integer(System.identityHashCode(proxy)); - } - else if (method.getName().equals("close")) { - // Handle close method: don't pass the call on if we are - // suppressing close calls. - if (dataSource.completeCloseCall((Connection) proxy)) { - return null; - } - else { - target.close(); - return null; - } - } - else if (method.getName().equals("getTargetConnection")) { - // Handle getTargetConnection method: return underlying - // Connection. - return this.target; + switch (method.getName()) { + case "equals": + // Only consider equal when proxies are identical. + return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE); + case "hashCode": + // Use hashCode of Connection proxy. + return System.identityHashCode(proxy); + case "close": + // Handle close method: don't pass the call on if we are + // suppressing close calls. + if (dataSource.completeCloseCall((Connection) proxy)) { + return null; + } + else { + target.close(); + return null; + } + case "getTargetConnection": + // Handle getTargetConnection method: return underlying + // Connection. + return this.target; } // Invoke method on target Connection. @@ -306,10 +302,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi */ @Override public boolean isWrapperFor(Class iface) throws SQLException { - if (iface.isAssignableFrom(SmartDataSource.class) || iface.isAssignableFrom(dataSource.getClass())) { - return true; - } - return false; + return iface.isAssignableFrom(SmartDataSource.class) || iface.isAssignableFrom(dataSource.getClass()); } /** @@ -334,7 +327,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource); + Assert.notNull(dataSource, "DataSource is required"); } /** @@ -348,14 +341,8 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi try { invoker.prepare(); return (Logger) invoker.invoke(); - } catch (ClassNotFoundException cnfe) { - throw new SQLFeatureNotSupportedException(cnfe); - } catch (NoSuchMethodException nsme) { + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException nsme) { throw new SQLFeatureNotSupportedException(nsme); - } catch (IllegalAccessException iae) { - throw new SQLFeatureNotSupportedException(iae); - } catch (InvocationTargetException ite) { - throw new SQLFeatureNotSupportedException(ite); } } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateCursorItemReader.java index e4eb0378a..6552b3d76 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateCursorItemReader.java @@ -115,7 +115,7 @@ public class HibernateCursorItemReader extends AbstractItemCountingItemStream * * @param queryProvider Hibernate query provider */ - public void setQueryProvider(HibernateQueryProvider queryProvider) { + public void setQueryProvider(HibernateQueryProvider queryProvider) { helper.setQueryProvider(queryProvider); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java index 154b45bcb..1fcc3b03f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java @@ -40,6 +40,7 @@ import org.springframework.util.StringUtils; * @author Dave Syer * */ +@SuppressWarnings("rawtype") public class HibernateItemReaderHelper implements InitializingBean { private SessionFactory sessionFactory; @@ -48,7 +49,7 @@ public class HibernateItemReaderHelper implements InitializingBean { private String queryName = ""; - private HibernateQueryProvider queryProvider; + private HibernateQueryProvider queryProvider; private boolean useStatelessSession = true; @@ -73,7 +74,7 @@ public class HibernateItemReaderHelper implements InitializingBean { /** * @param queryProvider Hibernate query provider */ - public void setQueryProvider(HibernateQueryProvider queryProvider) { + public void setQueryProvider(HibernateQueryProvider queryProvider) { this.queryProvider = queryProvider; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernatePagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernatePagingItemReader.java index 5fac72b50..2f4172c30 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernatePagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernatePagingItemReader.java @@ -108,7 +108,7 @@ public class HibernatePagingItemReader extends AbstractPagingItemReader * * @param queryProvider Hibernate query provider */ - public void setQueryProvider(HibernateQueryProvider queryProvider) { + public void setQueryProvider(HibernateQueryProvider queryProvider) { helper.setQueryProvider(queryProvider); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ItemPreparedStatementSetter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ItemPreparedStatementSetter.java index e3ea33f8c..c345f3acc 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ItemPreparedStatementSetter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ItemPreparedStatementSetter.java @@ -31,6 +31,7 @@ public interface ItemPreparedStatementSetter { /** * Set parameter values on the given PreparedStatement as determined from * the provided item. + * @param item the item to obtain the values from * @param ps the PreparedStatement to invoke setter methods on * @throws SQLException if a SQLException is encountered (i.e. there is no * need to catch SQLException) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java index de37aa901..a99b418c5 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java @@ -142,7 +142,7 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean { public void afterPropertiesSet() { Assert.notNull(namedParameterJdbcTemplate, "A DataSource or a NamedParameterJdbcTemplate is required."); Assert.notNull(sql, "An SQL statement is required."); - List namedParameters = new ArrayList(); + List namedParameters = new ArrayList<>(); parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql, namedParameters); if (namedParameters.size() > 0) { if (parameterCount != namedParameters.size()) { @@ -158,7 +158,7 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean { /* (non-Javadoc) * @see org.springframework.batch.item.ItemWriter#write(java.util.List) */ - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void write(final List items) throws Exception { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java index 6138f0608..9fcb6bb48 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java @@ -68,7 +68,7 @@ public class JdbcCursorItemReader extends AbstractCursorItemReader { /** * Set the RowMapper to be used for all calls to read(). * - * @param rowMapper + * @param rowMapper the mapper used to map each item */ public void setRowMapper(RowMapper rowMapper) { this.rowMapper = rowMapper; @@ -79,7 +79,7 @@ public class JdbcCursorItemReader extends AbstractCursorItemReader { * should be a complete and valid SQL statement, as it will be run directly * without any modification. * - * @param sql + * @param sql SQL statement */ public void setSql(String sql) { this.sql = sql; @@ -89,7 +89,7 @@ public class JdbcCursorItemReader extends AbstractCursorItemReader { * Set the PreparedStatementSetter to use if any parameter values that need * to be set in the supplied query. * - * @param preparedStatementSetter + * @param preparedStatementSetter PreparedStatementSetter responsible for filling out the statement */ public void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter) { this.preparedStatementSetter = preparedStatementSetter; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java index 805e6af67..6a5d8195a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java @@ -163,14 +163,14 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(dataSource); + Assert.notNull(dataSource, "DataSource may not be null"); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); if (fetchSize != VALUE_NOT_SET) { jdbcTemplate.setFetchSize(fetchSize); } jdbcTemplate.setMaxRows(getPageSize()); namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); - Assert.notNull(queryProvider); + Assert.notNull(queryProvider, "QueryProvider may not be null"); queryProvider.init(dataSource); this.firstPageSql = queryProvider.generateFirstPageQuery(getPageSize()); this.remainingPagesSql = queryProvider.generateRemainingPagesQuery(getPageSize()); @@ -180,7 +180,7 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme @SuppressWarnings("unchecked") protected void doReadPage() { if (results == null) { - results = new CopyOnWriteArrayList(); + results = new CopyOnWriteArrayList<>(); } else { results.clear(); @@ -253,7 +253,7 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme startAfterValues = (Map) executionContext.get(getExecutionContextKey(START_AFTER_VALUE)); if(startAfterValues == null) { - startAfterValues = new LinkedHashMap(); + startAfterValues = new LinkedHashMap<>(); } } @@ -285,7 +285,7 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme } private Map getParameterMap(Map values, Map sortKeyValues) { - Map parameterMap = new LinkedHashMap(); + Map parameterMap = new LinkedHashMap<>(); if (values != null) { parameterMap.putAll(values); } @@ -301,14 +301,14 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme } private List getParameterList(Map values, Map sortKeyValue) { - SortedMap sm = new TreeMap(); + SortedMap sm = new TreeMap<>(); if (values != null) { sm.putAll(values); } - List parameterList = new ArrayList(); + List parameterList = new ArrayList<>(); parameterList.addAll(sm.values()); if (sortKeyValue != null && sortKeyValue.size() > 0) { - List> keys = new ArrayList>(sortKeyValue.entrySet()); + List> keys = new ArrayList<>(sortKeyValue.entrySet()); for(int i = 0; i < keys.size(); i++) { for(int j = 0; j < i; j++) { @@ -328,7 +328,7 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme private class PagingRowMapper implements RowMapper { @Override public T mapRow(ResultSet rs, int rowNum) throws SQLException { - startAfterValues = new LinkedHashMap(); + startAfterValues = new LinkedHashMap<>(); for (Map.Entry sortKey : queryProvider.getSortKeys().entrySet()) { startAfterValues.put(sortKey.getKey(), rs.getObject(sortKey.getKey())); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcParameterUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcParameterUtils.java index 7c6aafe13..1858db9e5 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcParameterUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcParameterUtils.java @@ -45,6 +45,8 @@ public class JdbcParameterUtils { * suite the batch processing requirements. * * @param sql String to search in. Returns 0 if the given String is null. + * @param namedParameterHolder holder for the named parameters + * @return the number of named parameter placeholders */ public static int countParameterPlaceholders(String sql, List namedParameterHolder ) { if (sql == null) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaPagingItemReader.java index 9500384fa..fbd07dc79 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaPagingItemReader.java @@ -89,7 +89,7 @@ public class JpaPagingItemReader extends AbstractPagingItemReader { private EntityManager entityManager; - private final Map jpaPropertyMap = new HashMap(); + private final Map jpaPropertyMap = new HashMap<>(); private String queryString; @@ -136,7 +136,7 @@ public class JpaPagingItemReader extends AbstractPagingItemReader { * particular transaction. (e.g. Hibernate with a JTA transaction). NOTE: may cause * problems in guaranteeing the object consistency in the EntityManagerFactory. * - * @param transacted + * @param transacted indicator */ public void setTransacted(boolean transacted) { this.transacted = transacted; @@ -147,12 +147,8 @@ public class JpaPagingItemReader extends AbstractPagingItemReader { super.afterPropertiesSet(); if (queryProvider == null) { - Assert.notNull(entityManagerFactory); - Assert.hasLength(queryString); - } - // making sure that the appropriate (JPA) query provider is set - else { - Assert.isTrue(queryProvider != null, "JPA query provider must be set"); + Assert.notNull(entityManagerFactory, "EntityManager is required when queryProvider is null"); + Assert.hasLength(queryString, "Query string is required when queryProvider is null"); } } @@ -209,7 +205,7 @@ public class JpaPagingItemReader extends AbstractPagingItemReader { } if (results == null) { - results = new CopyOnWriteArrayList(); + results = new CopyOnWriteArrayList<>(); } else { results.clear(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/PagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/PagingQueryProvider.java index 91861c1ef..ee88aa455 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/PagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/PagingQueryProvider.java @@ -16,8 +16,8 @@ package org.springframework.batch.item.database; -import javax.sql.DataSource; import java.util.Map; +import javax.sql.DataSource; /** @@ -34,6 +34,7 @@ public interface PagingQueryProvider { * Initialize the query provider using the provided {@link DataSource} if necessary. * * @param dataSource DataSource to use for any initialization + * @throws Exception for errors when initializing */ void init(DataSource dataSource) throws Exception; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/StoredProcedureItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/StoredProcedureItemReader.java index 0375da01c..983619841 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/StoredProcedureItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/StoredProcedureItemReader.java @@ -81,7 +81,7 @@ public class StoredProcedureItemReader extends AbstractCursorItemReader { /** * Set the RowMapper to be used for all calls to read(). * - * @param rowMapper + * @param rowMapper the RowMapper to use to map the results */ public void setRowMapper(RowMapper rowMapper) { this.rowMapper = rowMapper; @@ -92,7 +92,7 @@ public class StoredProcedureItemReader extends AbstractCursorItemReader { * should be a complete and valid SQL statement, as it will be run directly * without any modification. * - * @param sprocedureName + * @param sprocedureName the SQL used to call the statement */ public void setProcedureName(String sprocedureName) { this.procedureName = sprocedureName; @@ -102,7 +102,7 @@ public class StoredProcedureItemReader extends AbstractCursorItemReader { * Set the PreparedStatementSetter to use if any parameter values that need * to be set in the supplied query. * - * @param preparedStatementSetter + * @param preparedStatementSetter used to populate the SQL */ public void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter) { this.preparedStatementSetter = preparedStatementSetter; @@ -120,6 +120,8 @@ public class StoredProcedureItemReader extends AbstractCursorItemReader { /** * Set whether this stored procedure is a function. + * + * @param function indicator */ public void setFunction(boolean function) { this.function = function; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilder.java index ccc6185c7..fa347bf20 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilder.java @@ -45,7 +45,7 @@ public class HibernateCursorItemReaderBuilder { private int fetchSize; - private HibernateQueryProvider queryProvider; + private HibernateQueryProvider queryProvider; private String queryString; @@ -124,7 +124,7 @@ public class HibernateCursorItemReaderBuilder { * @return this instance for method chaining * @see HibernateCursorItemReader#setQueryProvider(HibernateQueryProvider) */ - public HibernateCursorItemReaderBuilder queryProvider(HibernateQueryProvider queryProvider) { + public HibernateCursorItemReaderBuilder queryProvider(HibernateQueryProvider queryProvider) { this.queryProvider = queryProvider; return this; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilder.java index 7b8ffc0ad..01401d0be 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilder.java @@ -167,6 +167,7 @@ public class JdbcBatchItemWriterBuilder { * * @return a {@link JdbcBatchItemWriter} */ + @SuppressWarnings("unchecked") public JdbcBatchItemWriter build() { Assert.state(this.dataSource != null || this.namedParameterJdbcTemplate != null, "Either a DataSource or a NamedParameterJdbcTemplate is required"); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/AbstractHibernateQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/AbstractHibernateQueryProvider.java index 4b03d92ed..54bb65335 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/AbstractHibernateQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/AbstractHibernateQueryProvider.java @@ -35,7 +35,7 @@ import org.hibernate.StatelessSession; * @since 2.1 * */ -public abstract class AbstractHibernateQueryProvider implements HibernateQueryProvider { +public abstract class AbstractHibernateQueryProvider implements HibernateQueryProvider { private StatelessSession statelessSession; private Session statefulSession; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/AbstractJpaQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/AbstractJpaQueryProvider.java index 118dc34bb..0386464a7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/AbstractJpaQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/AbstractJpaQueryProvider.java @@ -43,7 +43,7 @@ public abstract class AbstractJpaQueryProvider implements JpaQueryProvider, Init * {@link HibernateQueryProvider} to participate in a user's managed transaction. *

* - * @param entityManager + * @param entityManager EntityManager to use */ @Override public void setEntityManager(EntityManager entityManager) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/HibernateQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/HibernateQueryProvider.java index ee83a95f7..537158a7e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/HibernateQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/HibernateQueryProvider.java @@ -33,7 +33,7 @@ import org.springframework.batch.item.ItemReader; * @since 2.1 * */ -public interface HibernateQueryProvider { +public interface HibernateQueryProvider { /** *

@@ -43,7 +43,7 @@ public interface HibernateQueryProvider { * * @return created query */ - Query createQuery(); + Query createQuery(); /** *

diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java index d71d6e030..01398f004 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java @@ -16,6 +16,12 @@ package org.springframework.batch.item.database.support; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import javax.sql.DataSource; + import org.springframework.batch.item.database.JdbcParameterUtils; import org.springframework.batch.item.database.Order; import org.springframework.batch.item.database.PagingQueryProvider; @@ -23,12 +29,6 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import javax.sql.DataSource; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - /** * Abstract SQL Paging Query Provider to serve as a base class for all provided * SQL paging query providers. @@ -182,7 +182,7 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi */ @Override public void init(DataSource dataSource) throws Exception { - Assert.notNull(dataSource); + Assert.notNull(dataSource, "A DataSource is required"); Assert.hasLength(selectClause, "selectClause must be specified"); Assert.hasLength(fromClause, "fromClause must be specified"); Assert.notEmpty(sortKeys, "sortKey must be specified"); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java index de46a6930..9e3941eab 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java @@ -152,7 +152,7 @@ InitializingBean { /** * Setter for resource. Represents a file that can be written. * - * @param resource + * @param resource the resource to be written to */ @Override public void setResource(Resource resource) { @@ -208,7 +208,7 @@ InitializingBean { * update. Setting this to false means that it will always start at the * beginning on a restart. * - * @param saveState + * @param saveState if true, state will be persisted */ public void setSaveState(boolean saveState) { this.saveState = saveState; @@ -448,14 +448,14 @@ InitializingBean { } /** - * @param append + * @param append if true, append to previously created file */ public void setAppendAllowed(boolean append) { this.append = append; } /** - * @param executionContext + * @param executionContext state from which to restore writing from */ public void restoreFrom(ExecutionContext executionContext) { lastMarkedByteOffsetPosition = executionContext.getLong(getExecutionContextKey(RESTART_DATA_NAME)); @@ -470,14 +470,14 @@ InitializingBean { } /** - * @param shouldDeleteIfExists + * @param shouldDeleteIfExists indicator */ public void setDeleteIfExists(boolean shouldDeleteIfExists) { this.shouldDeleteIfExists = shouldDeleteIfExists; } /** - * @param encoding + * @param encoding file encoding */ public void setEncoding(String encoding) { this.encoding = encoding; @@ -527,7 +527,7 @@ InitializingBean { } /** - * @param line + * @param line String to be written to the file * @throws IOException */ public void write(String line) throws IOException { @@ -542,7 +542,7 @@ InitializingBean { /** * Truncate the output at the last known good point. * - * @throws IOException + * @throws IOException if unable to work with file */ public void truncate() throws IOException { fileChannel.truncate(lastMarkedByteOffsetPosition); @@ -552,7 +552,7 @@ InitializingBean { /** * Creates the buffered writer for the output file channel based on * configuration information. - * @throws IOException + * @throws IOException if unable to initialize buffer */ private void initializeBufferedWriter() throws IOException { @@ -574,7 +574,8 @@ InitializingBean { } } - Assert.state(outputBufferedWriter != null); + Assert.state(outputBufferedWriter != null, + "Unable to initialize buffered writer"); // in case of restarting reset position to last committed point if (restarted) { checkFileSize(); @@ -596,12 +597,7 @@ InitializingBean { try { final FileChannel channel = fileChannel; if (transactional) { - TransactionAwareBufferedWriter writer = new TransactionAwareBufferedWriter(channel, new Runnable() { - @Override - public void run() { - closeStream(); - } - }); + TransactionAwareBufferedWriter writer = new TransactionAwareBufferedWriter(channel, () -> closeStream()); writer.setEncoding(encoding); writer.setForceSync(forceSync); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java index e145fd142..bcec4b962 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java @@ -380,7 +380,7 @@ public class FlatFileItemReaderBuilder { * Builds the {@link FlatFileItemReader}. * * @return a {@link FlatFileItemReader} - * @throws Exception + * @throws Exception if an error occurs during construction */ public FlatFileItemReader build() throws Exception { if(this.saveState) { @@ -574,7 +574,7 @@ public class FlatFileItemReaderBuilder { * Returns a {@link DelimitedLineTokenizer} * * @return {@link DelimitedLineTokenizer} - * @throws Exception + * @throws Exception if an error occurs during construction */ public DelimitedLineTokenizer build() throws Exception { Assert.notNull(this.fieldSetFactory, "A FieldSetFactory is required."); 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 2388f4362..08b192b90 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 @@ -16,6 +16,15 @@ package org.springframework.batch.item.file.mapping; +import java.beans.PropertyEditor; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.support.DefaultPropertyEditorRegistrar; import org.springframework.beans.BeanWrapperImpl; @@ -32,15 +41,6 @@ import org.springframework.util.ReflectionUtils; import org.springframework.validation.BindException; import org.springframework.validation.DataBinder; -import java.beans.PropertyEditor; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - /** * {@link FieldSetMapper} implementation based on bean property paths. The * {@link FieldSet} to be mapped should have field name meta data corresponding @@ -198,7 +198,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar * {@link #initBinder(DataBinder)} and * {@link #registerCustomEditors(PropertyEditorRegistry)}. * - * @param target + * @param target Object to bind to * @return a {@link DataBinder} that can be used to bind properties to the * target. */ @@ -243,9 +243,8 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar } /** - * @param bean - * @param properties - * @return + * @param bean Object to get properties for + * @param properties Properties to retrieve */ private Properties getBeanProperties(Object bean, Properties properties) { @@ -254,9 +253,9 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar // Map from field names to property names DistanceHolder distanceKey = new DistanceHolder(cls, distanceLimit); if (!propertiesMatched.containsKey(distanceKey)) { - propertiesMatched.putIfAbsent(distanceKey, new ConcurrentHashMap()); + propertiesMatched.putIfAbsent(distanceKey, new ConcurrentHashMap<>()); } - Map matches = new HashMap(propertiesMatched.get(distanceKey)); + Map matches = new HashMap<>(propertiesMatched.get(distanceKey)); @SuppressWarnings({ "unchecked", "rawtypes" }) Set keys = new HashSet(properties.keySet()); @@ -285,7 +284,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar } } - propertiesMatched.replace(distanceKey, new ConcurrentHashMap(matches)); + propertiesMatched.replace(distanceKey, new ConcurrentHashMap<>(matches)); return properties; } @@ -378,7 +377,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar * {@link #mapFieldSet(FieldSet)} will fail of the FieldSet contains fields * that cannot be mapped to the bean. * - * @param strict + * @param strict indicator */ public void setStrict(boolean strict) { this.strict = strict; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/FieldSetMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/FieldSetMapper.java index c8a570053..7e25328f9 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/FieldSetMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/FieldSetMapper.java @@ -35,6 +35,7 @@ public interface FieldSetMapper { * Method used to map data obtained from a {@link FieldSet} into an object. * * @param fieldSet the {@link FieldSet} to map + * @return the populated object * @throws BindException if there is a problem with the binding */ T mapFieldSet(FieldSet fieldSet) throws BindException; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/DefaultRecordSeparatorPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/DefaultRecordSeparatorPolicy.java index e8315813b..1834d9bb0 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/DefaultRecordSeparatorPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/DefaultRecordSeparatorPolicy.java @@ -45,6 +45,8 @@ public class DefaultRecordSeparatorPolicy extends SimpleRecordSeparatorPolicy { /** * Convenient constructor with quote character as parameter. + * + * @param quoteCharacter value used to indicate a quoted string */ public DefaultRecordSeparatorPolicy(String quoteCharacter) { this(quoteCharacter, CONTINUATION); @@ -53,6 +55,9 @@ public class DefaultRecordSeparatorPolicy extends SimpleRecordSeparatorPolicy { /** * Convenient constructor with quote character and continuation marker as * parameters. + * + * @param quoteCharacter value used to indicate a quoted string + * @param continuation value used to indicate a line continuation */ public DefaultRecordSeparatorPolicy(String quoteCharacter, String continuation) { super(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/SuffixRecordSeparatorPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/SuffixRecordSeparatorPolicy.java index b04b400c4..acd9ed492 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/SuffixRecordSeparatorPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/SuffixRecordSeparatorPolicy.java @@ -38,7 +38,7 @@ public class SuffixRecordSeparatorPolicy extends DefaultRecordSeparatorPolicy { /** * Lines ending in this terminator String signal the end of a record. * - * @param suffix + * @param suffix suffix to indicate the end of a record */ public void setSuffix(String suffix) { this.suffix = suffix; @@ -48,7 +48,7 @@ public class SuffixRecordSeparatorPolicy extends DefaultRecordSeparatorPolicy { * Flag to indicate that the decision to terminate a record should ignore * whitespace at the end of the line. * - * @param ignoreWhitespace + * @param ignoreWhitespace indicator */ public void setIgnoreWhitespace(boolean ignoreWhitespace) { this.ignoreWhitespace = ignoreWhitespace; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java index 8812c467d..985cf8731 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java @@ -77,7 +77,7 @@ public abstract class AbstractLineTokenizer implements LineTokenizer { * Setter for column names. Optional, but if set, then all lines must have * as many or fewer tokens. * - * @param names + * @param names names of each column */ public void setNames(String[] names) { this.names = names==null ? null : Arrays.asList(names).toArray(new String[names.length]); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/Alignment.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/Alignment.java index a55e292e0..7710bd7b1 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/Alignment.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/Alignment.java @@ -29,10 +29,6 @@ public enum Alignment { private String code; private String label; - /** - * @param code - * @param label - */ private Alignment(String code, String label) { Assert.notNull(code, "'code' must not be null"); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java index 71efe5ab7..db2d78070 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java @@ -102,8 +102,8 @@ public class DefaultFieldSet implements FieldSet { * @see FieldSet#readString(String) */ public DefaultFieldSet(String[] tokens, String[] names) { - Assert.notNull(tokens); - Assert.notNull(names); + Assert.notNull(tokens, "Tokens must not be null"); + Assert.notNull(names, "Names must not be null"); if (tokens.length != names.length) { throw new IllegalArgumentException("Field names must be same length as values: names=" + Arrays.asList(names) + ", values=" + Arrays.asList(tokens)); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java index 5ebb519b6..b3d9b043b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java @@ -80,7 +80,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer * @param delimiter the desired delimiter. This is required */ public DelimitedLineTokenizer(String delimiter) { - Assert.notNull(delimiter); + Assert.notNull(delimiter, "A delimiter is required"); Assert.state(!delimiter.equals(String.valueOf(DEFAULT_QUOTE_CHARACTER)), "[" + DEFAULT_QUOTE_CHARACTER + "] is not allowed as delimiter for tokenizers."); @@ -91,7 +91,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer /** * Setter for the delimiter character. * - * @param delimiter + * @param delimiter the String used as a delimiter */ public void setDelimiter(String delimiter) { this.delimiter = delimiter; @@ -106,7 +106,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer * @param includedFields the included fields to set */ public void setIncludedFields(int[] includedFields) { - this.includedFields = new HashSet(); + this.includedFields = new HashSet<>(); for (int i : includedFields) { this.includedFields.add(i); } @@ -139,7 +139,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer @Override protected List doTokenize(String line) { - List tokens = new ArrayList(); + List tokens = new ArrayList<>(); // line is never null in current implementation // line is checked in parent: AbstractLineTokenizer.tokenize() @@ -281,6 +281,6 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer @Override public void afterPropertiesSet() throws Exception { - Assert.state(null != delimiter && 0 != delimiter.length()); + Assert.hasLength(this.delimiter, "A delimiter is required"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ExtractorLineAggregator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ExtractorLineAggregator.java index 48838e5bb..6fdd4d2a2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ExtractorLineAggregator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ExtractorLineAggregator.java @@ -50,7 +50,7 @@ public abstract class ExtractorLineAggregator implements LineAggregator { */ @Override public String aggregate(T item) { - Assert.notNull(item); + Assert.notNull(item, "Item is required"); Object[] fields = this.fieldExtractor.extract(item); // diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FormatterLineAggregator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FormatterLineAggregator.java index 8b6f41fa2..bd1d20aea 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FormatterLineAggregator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FormatterLineAggregator.java @@ -78,7 +78,7 @@ public class FormatterLineAggregator extends ExtractorLineAggregator { @Override protected String doAggregate(Object[] fields) { - Assert.notNull(format); + Assert.notNull(format, "A format is required"); String value = String.format(locale, format, fields); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/LdifReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/LdifReader.java index c54a58399..f11b12d66 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/LdifReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/LdifReader.java @@ -162,7 +162,7 @@ public class LdifReader extends AbstractItemCountingItemStreamItemReader extends AbstractItemCountingItemStreamItemRead public void afterPropertiesSet() throws Exception { Assert.notNull(resource, "A resource is required to parse."); - Assert.notNull(ldifParser); + Assert.notNull(ldifParser, "A parser is required"); } } \ No newline at end of file diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/util/FileUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/util/FileUtils.java index c9b244030..49b5458b6 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/util/FileUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/util/FileUtils.java @@ -51,7 +51,7 @@ public final class FileUtils { */ public static void setUpOutputFile(File file, boolean restarted, boolean append, boolean overwriteOutputFile) { - Assert.notNull(file); + Assert.notNull(file, "An output file is required"); try { if (!restarted) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java index 522de3719..493b5d480 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java @@ -352,7 +352,7 @@ ResourceAwareItemWriterItemStream, InitializingBean { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(marshaller); + Assert.notNull(marshaller, "A Marshaller is required"); if (rootTagName.contains("{")) { rootTagNamespace = rootTagName.replaceAll("\\{(.*)\\}.*", "$1"); rootTagName = rootTagName.replaceAll("\\{.*\\}(.*)", "$1"); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java index 197ff4f42..2cd9e0bf6 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java @@ -16,17 +16,18 @@ package org.springframework.batch.item.xml; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; - +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLEventWriter; import javax.xml.transform.Result; import javax.xml.transform.Source; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; /** * This class provides a little bit of indirection to avoid ugly conditional object creation. It is unfortunately @@ -69,10 +70,10 @@ public abstract class StaxUtils { Class clzz = ClassUtils.forName(staxSourceClassNameOnSpringOxm30, defaultClassLoader); // javax.xml.transform.Source - staxUtilsSourceMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxSource", new Class[]{ XMLEventReader.class}); + staxUtilsSourceMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxSource", XMLEventReader.class); // javax.xml.transform.Result - staxUtilsResultMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxResult", new Class[]{XMLEventWriter.class}); + staxUtilsResultMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxResult", XMLEventWriter.class); } else if (hasSpringWs15StaxSupport) { // javax.xml.transform.Source @@ -126,7 +127,7 @@ public abstract class StaxUtils { } public static XMLEventWriter getXmlEventWriter(Result r) throws Exception { - Method m = r.getClass().getDeclaredMethod("getXMLEventWriter", new Class[]{}); + Method m = r.getClass().getDeclaredMethod("getXMLEventWriter"); boolean accessible = m.isAccessible(); m.setAccessible(true); Object result = m.invoke(r); @@ -135,7 +136,7 @@ public abstract class StaxUtils { } public static XMLEventReader getXmlEventReader(Source s) throws Exception { - Method m = s.getClass().getDeclaredMethod("getXMLEventReader", new Class[]{}); + Method m = s.getClass().getDeclaredMethod("getXMLEventReader"); boolean accessible = m.isAccessible(); m.setAccessible(true); Object result = m.invoke(s); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/jsr/item/CheckpointSupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/jsr/item/CheckpointSupport.java index 62ae32e24..f148e75c5 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/jsr/item/CheckpointSupport.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/jsr/item/CheckpointSupport.java @@ -49,7 +49,7 @@ public abstract class CheckpointSupport extends ItemStreamSupport{ * @param checkpointKey key to store the checkpoint object with in the {@link ExecutionContext} */ public CheckpointSupport(String checkpointKey) { - Assert.hasText(checkpointKey); + Assert.hasText(checkpointKey, "checkpointKey is required"); this.checkpointKey = checkpointKey; } @@ -72,7 +72,7 @@ public abstract class CheckpointSupport extends ItemStreamSupport{ * Used to open a batch artifact with previously saved checkpoint information. * * @param checkpoint previously saved checkpoint object - * @throws Exception + * @throws Exception thrown by the implementation */ protected abstract void doOpen(Serializable checkpoint) throws Exception; @@ -94,7 +94,7 @@ public abstract class CheckpointSupport extends ItemStreamSupport{ * batch artifact. * * @return the current state of the batch artifact - * @throws Exception + * @throws Exception thrown by the implementation */ protected abstract Serializable doCheckpoint() throws Exception; @@ -113,7 +113,7 @@ public abstract class CheckpointSupport extends ItemStreamSupport{ /** * Used to close the underlying batch artifact * - * @throws Exception + * @throws Exception thrown by the underlying implementation */ protected abstract void doClose() throws Exception; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatContext.java index 4ece5f36e..d1f40f165 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatContext.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatContext.java @@ -54,6 +54,8 @@ public interface RepeatContext extends AttributeAccessor { /** * Public accessor for the complete flag. + * + * @return indicator if the repeat is complete */ boolean isCompleteOnly(); @@ -66,6 +68,8 @@ public interface RepeatContext extends AttributeAccessor { /** * Public accessor for the termination flag. If this flag is set then the * complete flag will also be. + * + * @return indicates if the repeat should terminate */ boolean isTerminateOnly(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java index 027baf6e0..177872992 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java @@ -43,12 +43,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler { protected final Log logger = LogFactory.getLog(RethrowOnThresholdExceptionHandler.class); - private Classifier exceptionClassifier = new Classifier() { - @Override - public RethrowOnThresholdExceptionHandler.IntegerHolder classify(Throwable classifiable) { - return ZERO; - } - }; + private Classifier exceptionClassifier = (Classifier) classifiable -> ZERO; private boolean useParent = false; @@ -82,7 +77,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler { for (Entry, Integer> entry : thresholds.entrySet()) { typeMap.put(entry.getKey(), new IntegerHolder(entry.getValue())); } - exceptionClassifier = new SubclassClassifier(typeMap, ZERO); + exceptionClassifier = new SubclassClassifier<>(typeMap, ZERO); } /** @@ -123,7 +118,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler { private final int value; /** - * @param value + * @param value value within holder */ public IntegerHolder(int value) { this.value = value; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java index 8400b395e..29d7d9c9d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java @@ -16,8 +16,14 @@ package org.springframework.batch.repeat.support; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.batch.repeat.CompletionPolicy; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; @@ -30,11 +36,6 @@ import org.springframework.batch.repeat.exception.ExceptionHandler; import org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy; import org.springframework.util.Assert; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - /** * Simple implementation and base class for batch templates implementing * {@link RepeatOperations}. Provides a framework including interceptors and @@ -76,7 +77,7 @@ public class RepeatTemplate implements RepeatOperations { * Set the listeners for this template, registering them for callbacks at * appropriate times in the iteration. * - * @param listeners + * @param listeners listeners to be used */ public void setListeners(RepeatListener[] listeners) { this.listeners = Arrays.asList(listeners).toArray(new RepeatListener[listeners.length]); @@ -85,10 +86,10 @@ public class RepeatTemplate implements RepeatOperations { /** * Register an additional listener. * - * @param listener + * @param listener a single listener to be added to the list */ public void registerListener(RepeatListener listener) { - List list = new ArrayList(Arrays.asList(listeners)); + List list = new ArrayList<>(Arrays.asList(listeners)); list.add(listener); listeners = list.toArray(new RepeatListener[list.size()]); } @@ -121,7 +122,7 @@ public class RepeatTemplate implements RepeatOperations { * @throws IllegalArgumentException if the argument is null */ public void setCompletionPolicy(CompletionPolicy terminationPolicy) { - Assert.notNull(terminationPolicy); + Assert.notNull(terminationPolicy, "CompletionPolicy is required"); this.completionPolicy = terminationPolicy; } @@ -172,8 +173,7 @@ public class RepeatTemplate implements RepeatOperations { // processing takes place. boolean running = !isMarkedComplete(context); - for (int i = 0; i < listeners.length; i++) { - RepeatListener interceptor = listeners[i]; + for (RepeatListener interceptor : listeners) { interceptor.open(context); running = running && !isMarkedComplete(context); if (!running) @@ -188,7 +188,7 @@ public class RepeatTemplate implements RepeatOperations { Collection throwables = state.getThrowables(); // Keep a separate list of exceptions we handled that need to be // rethrown - Collection deferred = new ArrayList(); + Collection deferred = new ArrayList<>(); try { @@ -361,6 +361,7 @@ public class RepeatTemplate implements RepeatOperations { * @param callback the callback to execute. * @param state maintained by the implementation. * @return a finished result. + * @throws Throwable any Throwable emitted during the iteration * * @see #isComplete(RepeatContext) * @see #createInternalState(RepeatContext) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java index c300cfc8c..ae57b1534 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java @@ -83,7 +83,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { * @throws IllegalArgumentException if the argument is null */ public void setTaskExecutor(TaskExecutor taskExecutor) { - Assert.notNull(taskExecutor); + Assert.notNull(taskExecutor, "A TaskExecutor is required"); this.taskExecutor = taskExecutor; } @@ -99,7 +99,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state) throws Throwable { - ExecutingRunnable runnable = null; + ExecutingRunnable runnable; ResultQueue queue = ((ResultQueueInternalState) state).getResultQueue(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java index 063a7a39f..18150e389 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java @@ -57,7 +57,7 @@ public class MethodInvokerUtils { Assert.isTrue(!paramsRequired, errorMsg); // if no method was found for the given parameters, and the // parameters aren't required, then try with no params - method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, new Class[] {}); + method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName); Assert.notNull(method, errorMsg); } return new SimpleMethodInvoker(object, method); @@ -66,8 +66,8 @@ public class MethodInvokerUtils { /** * Create a String representation of the array of parameter types. * - * @param paramTypes - * @return String + * @param paramTypes types of the parameters to be used + * @return String a String representation of those types */ public static String getParamTypesString(Class... paramTypes) { StringBuilder paramTypesList = new StringBuilder("("); @@ -116,22 +116,19 @@ public class MethodInvokerUtils { final Class targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource() .getTargetClass() : target.getClass(); if (mi != null) { - ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() { - @Override - public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { - Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType); - if (annotation != null) { - Class[] paramTypes = method.getParameterTypes(); - if (paramTypes.length > 0) { - String errorMsg = "The method [" + method.getName() + "] on target class [" - + targetClass.getSimpleName() + "] is incompatible with the signature [" - + getParamTypesString(expectedParamTypes) + "] expected for the annotation [" - + annotationType.getSimpleName() + "]."; + ReflectionUtils.doWithMethods(targetClass, method -> { + Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType); + if (annotation != null) { + Class[] paramTypes = method.getParameterTypes(); + if (paramTypes.length > 0) { + String errorMsg = "The method [" + method.getName() + "] on target class [" + + targetClass.getSimpleName() + "] is incompatible with the signature [" + + getParamTypesString(expectedParamTypes) + "] expected for the annotation [" + + annotationType.getSimpleName() + "]."; - Assert.isTrue(paramTypes.length == expectedParamTypes.length, errorMsg); - for (int i = 0; i < paramTypes.length; i++) { - Assert.isTrue(expectedParamTypes[i].isAssignableFrom(paramTypes[i]), errorMsg); - } + Assert.isTrue(paramTypes.length == expectedParamTypes.length, errorMsg); + for (int i = 0; i < paramTypes.length; i++) { + Assert.isTrue(expectedParamTypes[i].isAssignableFrom(paramTypes[i]), errorMsg); } } } @@ -162,17 +159,14 @@ public class MethodInvokerUtils { // Proxy with no target cannot have annotations return null; } - final AtomicReference annotatedMethod = new AtomicReference(); - ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() { - @Override - public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { - Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType); - if (annotation != null) { - Assert.isNull(annotatedMethod.get(), "found more than one method on target class [" - + targetClass.getSimpleName() + "] with the annotation type [" - + annotationType.getSimpleName() + "]."); - annotatedMethod.set(method); - } + final AtomicReference annotatedMethod = new AtomicReference<>(); + ReflectionUtils.doWithMethods(targetClass, method -> { + Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType); + if (annotation != null) { + Assert.isNull(annotatedMethod.get(), "found more than one method on target class [" + + targetClass.getSimpleName() + "] with the annotation type [" + + annotationType.getSimpleName() + "]."); + annotatedMethod.set(method); } }); Method method = annotatedMethod.get(); @@ -192,20 +186,17 @@ public class MethodInvokerUtils { * @return a MethodInvoker that calls a method on the delegate */ public static MethodInvoker getMethodInvokerForSingleArgument(Object target) { - final AtomicReference methodHolder = new AtomicReference(); - ReflectionUtils.doWithMethods(target.getClass(), new ReflectionUtils.MethodCallback() { - @Override - public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { - if (method.getParameterTypes() == null || method.getParameterTypes().length != 1) { - return; - } - if (method.getReturnType().equals(Void.TYPE) || ReflectionUtils.isEqualsMethod(method)) { - return; - } - Assert.state(methodHolder.get() == null, - "More than one non-void public method detected with single argument."); - methodHolder.set(method); + final AtomicReference methodHolder = new AtomicReference<>(); + ReflectionUtils.doWithMethods(target.getClass(), method -> { + if (method.getParameterTypes() == null || method.getParameterTypes().length != 1) { + return; } + if (method.getReturnType().equals(Void.TYPE) || ReflectionUtils.isEqualsMethod(method)) { + return; + } + Assert.state(methodHolder.get() == null, + "More than one non-void public method detected with single argument."); + methodHolder.set(method); }); Method method = methodHolder.get(); return new SimpleMethodInvoker(target, method); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/ReflectionUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/ReflectionUtils.java index 9bf0a2167..0fbdce3cd 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/ReflectionUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/ReflectionUtils.java @@ -15,13 +15,13 @@ */ package org.springframework.batch.support; -import org.springframework.core.annotation.AnnotationUtils; - import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.HashSet; import java.util.Set; +import org.springframework.core.annotation.AnnotationUtils; + /** * Provides reflection based utilities for Spring Batch that are not available * via Spring Core @@ -41,10 +41,11 @@ public class ReflectionUtils { * @param annotationType The type of annotation to look for * @return a set of {@link java.lang.reflect.Method} instances if any are found, an empty set if not. */ + @SuppressWarnings("rawtypes") public static final Set findMethod(Class clazz, Class annotationType) { Method [] declaredMethods = org.springframework.util.ReflectionUtils.getAllDeclaredMethods(clazz); - Set results = new HashSet(); + Set results = new HashSet<>(); for (Method curMethod : declaredMethods) { Annotation annotation = AnnotationUtils.findAnnotation(curMethod, annotationType); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java index 0ad66fda2..b3ed81c45 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java @@ -65,7 +65,7 @@ public class SimpleMethodInvoker implements MethodInvoker { this.method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, paramTypes); if (this.method == null) { // try with no params - this.method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, new Class[] {}); + this.method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName); } if (this.method == null) { throw new IllegalArgumentException("No methods found for name: [" + methodName + "] in class: [" diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java index d5e32dd6a..e59bbaf46 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java @@ -15,18 +15,19 @@ */ package org.springframework.batch.item.adapter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; + import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator.InvocationTargetThrowableWrapper; -import org.springframework.util.Assert; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Tests for {@link AbstractMethodInvokingDelegator} @@ -75,7 +76,7 @@ public class AbstractDelegatorTests { // using the arguments setter should work equally well foo.setName("foo"); - Assert.state(!foo.getName().equals(NEW_FOO_NAME)); + assertTrue(!foo.getName().equals(NEW_FOO_NAME)); delegator.setArguments(new Object[] { NEW_FOO_NAME }); delegator.afterPropertiesSet(); delegator.invokeDelegateMethod(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java index 417875e0a..7df2629cf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java @@ -240,7 +240,7 @@ public class MongoItemWriterTests { public void testResourceKeyCollision() throws Exception { final int limit = 5000; @SuppressWarnings("unchecked") - final MongoItemWriter[] writers = new MongoItemWriter[limit]; + List> writers = new ArrayList<>(limit); final String[] results = new String[limit]; for(int i = 0; i< limit; i++) { final int index = i; @@ -255,14 +255,14 @@ public class MongoItemWriterTests { } return null; }).when(mongoOperations).save(any(String.class)); - writers[i] = new MongoItemWriter<>(); - writers[i].setTemplate(mongoOperations); + writers.add(i, new MongoItemWriter<>()); + writers.get(i).setTemplate(mongoOperations); } new TransactionTemplate(transactionManager).execute((TransactionCallback) status -> { try { for(int i=0; i< limit; i++) { - writers[i].write(Collections.singletonList(String.valueOf(i))); + writers.get(i).write(Collections.singletonList(String.valueOf(i))); } } catch (Exception e) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java index 83031a852..984f1fd31 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java @@ -15,14 +15,6 @@ */ package org.springframework.batch.item.data; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -43,6 +35,15 @@ import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.repository.PagingAndSortingRepository; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@SuppressWarnings("serial") public class RepositoryItemReaderTests { private RepositoryItemReader reader; @@ -214,7 +215,7 @@ public class RepositoryItemReaderTests { public void testDifferentTypes() throws Exception { TestRepository differentRepository = mock(TestRepository.class); RepositoryItemReader reader = new RepositoryItemReader(); - sorts = new HashMap(); + sorts = new HashMap<>(); sorts.put("id", Direction.ASC); reader.setRepository(differentRepository); reader.setPageSize(1); @@ -240,14 +241,14 @@ public class RepositoryItemReaderTests { reader.setCurrentItemCount(3); reader.setPageSize(2); - PageRequest request = new PageRequest(1, 2, new Sort(Direction.ASC, "id")); - when(repository.findAll(request)).thenReturn(new PageImpl(new ArrayList() {{ + PageRequest request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id")); + when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList() {{ add("3"); add("4"); }})); - request = new PageRequest(2, 2, new Sort(Direction.ASC, "id")); - when(repository.findAll(request)).thenReturn(new PageImpl(new ArrayList(){{ + request = PageRequest.of(2, 2, new Sort(Direction.ASC, "id")); + when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList(){{ add("5"); add("6"); }})); @@ -267,14 +268,14 @@ public class RepositoryItemReaderTests { reader.setCurrentItemCount(3); reader.setPageSize(2); - PageRequest request = new PageRequest(1, 2, new Sort(Direction.ASC, "id")); - when(repository.findAll(request)).thenReturn(new PageImpl(new ArrayList(){{ + PageRequest request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id")); + when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList(){{ add("3"); add("4"); }})); - request = new PageRequest(2, 2, new Sort(Direction.ASC, "id")); - when(repository.findAll(request)).thenReturn(new PageImpl(new ArrayList() {{ + request = PageRequest.of(2, 2, new Sort(Direction.ASC, "id")); + when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList() {{ add("5"); add("6"); }})); @@ -298,14 +299,14 @@ public class RepositoryItemReaderTests { public void testResetOfPage() throws Exception { reader.setPageSize(2); - PageRequest request = new PageRequest(0, 2, new Sort(Direction.ASC, "id")); - when(repository.findAll(request)).thenReturn(new PageImpl(new ArrayList(){{ + PageRequest request = PageRequest.of(0, 2, new Sort(Direction.ASC, "id")); + when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList(){{ add("1"); add("2"); }})); - request = new PageRequest(1, 2, new Sort(Direction.ASC, "id")); - when(repository.findAll(request)).thenReturn(new PageImpl(new ArrayList() {{ + request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id")); + when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList() {{ add("3"); add("4"); }})); @@ -324,7 +325,7 @@ public class RepositoryItemReaderTests { assertEquals("3", reader.read()); } - public static interface TestRepository extends PagingAndSortingRepository { + public interface TestRepository extends PagingAndSortingRepository, Long> { Page findFirstNames(Pageable pageable); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDataSourceItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDataSourceItemReaderIntegrationTests.java index 164069472..80caeb6e0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDataSourceItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDataSourceItemReaderIntegrationTests.java @@ -29,10 +29,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -233,10 +233,10 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests { getAsItemStream(reader).update(executionContext); Foo foo2 = reader.read(); - Assert.state(!foo2.equals(foo1)); + assertTrue(!foo2.equals(foo1)); Foo foo3 = reader.read(); - Assert.state(!foo2.equals(foo3)); + assertTrue(!foo2.equals(foo3)); getAsItemStream(reader).close(); @@ -263,10 +263,10 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests { Foo foo1 = reader.read(); Foo foo2 = reader.read(); - Assert.state(!foo2.equals(foo1)); + assertTrue(!foo2.equals(foo1)); Foo foo3 = reader.read(); - Assert.state(!foo2.equals(foo3)); + assertTrue(!foo2.equals(foo3)); getAsItemStream(reader).close(); @@ -292,10 +292,10 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests { getAsItemStream(reader).update(executionContext); Foo foo2 = reader.read(); - Assert.state(!foo2.equals(foo1)); + assertTrue(!foo2.equals(foo1)); Foo foo3 = reader.read(); - Assert.state(!foo2.equals(foo3)); + assertTrue(!foo2.equals(foo3)); getAsItemStream(reader).close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java index 23fcd75e4..7a6515a06 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java @@ -15,19 +15,20 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; - import javax.sql.DataSource; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.sample.Foo; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.junit.Before; -import org.junit.After; -import org.junit.Test; + +import static org.junit.Assert.assertEquals; public abstract class AbstractDatabaseItemStreamItemReaderTests extends AbstractItemStreamItemReaderTests { @@ -49,7 +50,6 @@ public abstract class AbstractDatabaseItemStreamItemReaderTests extends Abstract /** * Sub-classes can override this and create their own context. - * @throws Exception */ protected void initializeContext() throws Exception { ctx = new ClassPathXmlApplicationContext("org/springframework/batch/item/database/data-source-context.xml"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernatePagingItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernatePagingItemReaderIntegrationTests.java index 08ade7d8d..444ef1579 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernatePagingItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernatePagingItemReaderIntegrationTests.java @@ -17,10 +17,10 @@ package org.springframework.batch.item.database; import org.hibernate.SessionFactory; import org.hibernate.StatelessSession; + import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.sample.Foo; import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; /** @@ -37,7 +37,7 @@ AbstractGenericDataSourceItemReaderIntegrationTests { LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean(); factoryBean.setDataSource(dataSource); - factoryBean.setMappingLocations(new Resource[] { new ClassPathResource("Foo.hbm.xml", getClass()) }); + factoryBean.setMappingLocations(new ClassPathResource("Foo.hbm.xml", getClass())); customizeSessionFactory(factoryBean); factoryBean.afterPropertiesSet(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java index 0ff93372e..cbc7e04e7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java @@ -43,8 +43,8 @@ import org.springframework.jdbc.datasource.init.DataSourceInitializer; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.test.util.ReflectionTestUtils; -import static junit.framework.Assert.assertTrue; -import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderTests.java index d6af026ac..2b03b64e4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderTests.java @@ -22,8 +22,8 @@ import org.hibernate.query.NativeQuery; import org.junit.Test; import org.springframework.batch.item.database.orm.HibernateNativeQueryProvider; -import org.springframework.util.Assert; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -53,7 +53,7 @@ public class HibernateNativeQueryProviderTests { when(query.addEntity(Foo.class)).thenReturn(query); hibernateQueryProvider.setStatelessSession(session); - Assert.notNull(hibernateQueryProvider.createQuery()); + assertNotNull(hibernateQueryProvider.createQuery()); } @@ -69,7 +69,7 @@ public class HibernateNativeQueryProviderTests { when(query.addEntity(Foo.class)).thenReturn(query); hibernateQueryProvider.setSession(session); - Assert.notNull(hibernateQueryProvider.createQuery()); + assertNotNull(hibernateQueryProvider.createQuery()); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/JpaNativeQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/JpaNativeQueryProviderTests.java index 0390266d9..7d93736b9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/JpaNativeQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/JpaNativeQueryProviderTests.java @@ -16,17 +16,18 @@ package org.springframework.batch.item.database.support; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import javax.persistence.EntityManager; import javax.persistence.Query; import org.junit.Test; + import org.springframework.batch.item.database.orm.JpaNativeQueryProvider; import org.springframework.batch.item.sample.Foo; import org.springframework.util.Assert; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author Anatoly Polinsky * @author Dave Syer @@ -37,7 +38,7 @@ public class JpaNativeQueryProviderTests { private JpaNativeQueryProvider jpaQueryProvider; public JpaNativeQueryProviderTests() { - jpaQueryProvider = new JpaNativeQueryProvider(); + jpaQueryProvider = new JpaNativeQueryProvider<>(); jpaQueryProvider.setEntityClass(Foo.class); } @@ -53,6 +54,6 @@ public class JpaNativeQueryProviderTests { when(entityManager.createNativeQuery(sqlQuery, Foo.class)).thenReturn(query); jpaQueryProvider.setEntityManager(entityManager); - Assert.notNull(jpaQueryProvider.createQuery()); + Assert.notNull(jpaQueryProvider.createQuery(), "Query was null"); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java index 6897fbd0f..b61ef50d4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java @@ -15,14 +15,15 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; - import java.util.HashMap; +import java.util.Map; import org.junit.Test; import org.springframework.batch.item.database.Order; +import static org.junit.Assert.assertEquals; + /** * @author Thomas Risberg * @author Michael Minella @@ -100,12 +101,13 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide @Test public void testFirstPageSqlWithAliases() { + Map sorts = new HashMap<>(); + sorts.put("owner.id", Order.ASCENDING); + this.pagingQueryProvider = new MySqlPagingQueryProvider(); this.pagingQueryProvider.setSelectClause("SELECT owner.id as ownerid, first_name, last_name, dog_name "); this.pagingQueryProvider.setFromClause("FROM dog_owner owner INNER JOIN dog ON owner.id = dog.id "); - this.pagingQueryProvider.setSortKeys(new HashMap() {{ - put("owner.id", Order.ASCENDING); - }}); + this.pagingQueryProvider.setSortKeys(sorts); String firstPage = this.pagingQueryProvider.generateFirstPageQuery(5); String jumpToItemQuery = this.pagingQueryProvider.generateJumpToItemQuery(7, 5); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java index bb9f2aa76..2dedcf767 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java @@ -137,7 +137,7 @@ public class DelimitedLineTokenizerTests { tokenizer.tokenize("a b c"); } - @Test(expected=IllegalStateException.class) + @Test(expected=IllegalArgumentException.class) public void testDelimitedLineTokenizerEmptyString() throws Exception { DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(""); tokenizer.afterPropertiesSet(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/FileUtilsTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/FileUtilsTests.java index c220c23de..5e04bc0e7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/FileUtilsTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/FileUtilsTests.java @@ -15,17 +15,18 @@ */ package org.springframework.batch.item.util; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.batch.item.ItemStreamException; -import org.springframework.util.Assert; - import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.springframework.batch.item.ItemStreamException; +import org.springframework.util.Assert; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -57,7 +58,7 @@ public class FileUtilsTests { } file.delete(); - Assert.state(!file.exists()); + Assert.state(!file.exists(), "Delete failed"); FileUtils.setUpOutputFile(file, false, false, true); assertTrue(file.exists()); @@ -66,7 +67,7 @@ public class FileUtilsTests { writer.write("testString"); writer.close(); long size = file.length(); - Assert.state(size > 0); + Assert.state(size > 0, "Nothing was written"); FileUtils.setUpOutputFile(file, false, false, true); long newSize = file.length(); @@ -196,7 +197,7 @@ public class FileUtilsTests { @Before public void setUp() throws Exception { file.delete(); - Assert.state(!file.exists()); + Assert.state(!file.exists(), "File delete failed"); } @After diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java index cc36f7f87..31cdd9168 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java @@ -132,7 +132,7 @@ public class StaxEventItemWriterTests { @Test(expected = WriterNotOpenException.class) public void testAssertWriterIsInitialized() throws Exception { - StaxEventItemWriter writer = new StaxEventItemWriter(); + StaxEventItemWriter writer = new StaxEventItemWriter<>(); writer.write(Collections.singletonList("foo")); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java index 6f668a318..d67e34702 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java @@ -66,6 +66,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { } } + @SuppressWarnings("serial") public void testNotRethrownErrorLevel() throws Throwable { handler.setExceptionClassifier(new ClassifierSupport(Level.RETHROW) { @Override @@ -78,6 +79,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { assertNotNull(writer.toString()); } + @SuppressWarnings("serial") public void testNotRethrownWarnLevel() throws Throwable { handler.setExceptionClassifier(new ClassifierSupport(Level.RETHROW) { @Override @@ -90,6 +92,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { assertNotNull(writer.toString()); } + @SuppressWarnings("serial") public void testNotRethrownDebugLevel() throws Throwable { handler.setExceptionClassifier(new ClassifierSupport(Level.RETHROW) { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java index c2cea59d1..1d5966803 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java @@ -48,7 +48,7 @@ public class RepeatOperationsInterceptorTests extends TestCase { interceptor = new RepeatOperationsInterceptor(); target = new ServiceImpl(); ProxyFactory factory = new ProxyFactory(RepeatOperations.class.getClassLoader()); - factory.setInterfaces(new Class[] { Service.class }); + factory.setInterfaces(Service.class); factory.setTarget(target); service = (Service) factory.getProxy(); } @@ -101,7 +101,7 @@ public class RepeatOperationsInterceptorTests extends TestCase { fail("Expected IllegalStateException"); } catch (IllegalStateException e) { String message = e.getMessage(); - assertTrue("Wrong exception message: "+message, message.toLowerCase().indexOf("no result available")>=0); + assertTrue("Wrong exception message: "+message, message.toLowerCase().contains("no result available")); } assertEquals(1, calls.size()); } @@ -182,7 +182,7 @@ public class RepeatOperationsInterceptorTests extends TestCase { @Override public Method getMethod() { try { - return Object.class.getMethod("toString", new Class[0]); + return Object.class.getMethod("toString"); } catch (Exception e) { throw new RuntimeException(e); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java index 4b09a1760..df8d9e6df 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java @@ -16,11 +16,8 @@ package org.springframework.batch.repeat.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import org.junit.Test; + import org.springframework.batch.item.ItemReader; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; @@ -29,6 +26,10 @@ import org.springframework.batch.repeat.callback.NestedRepeatCallback; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.core.task.SimpleAsyncTaskExecutor; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Test various approaches to chunking of a batch. Not really a unit test, but * it should be fast. @@ -43,8 +44,6 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests { /** * Chunking using a dedicated TerminationPolicy. Transactions would be laid * on at the level of chunkTemplate.execute() or the surrounding callback. - * - * @throws Exception */ @Test public void testChunkedBatchWithTerminationPolicy() throws Exception { @@ -79,8 +78,6 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests { /** * Chunking with an asynchronous taskExecutor in the chunks. Transactions * have to be at the level of the business callback. - * - * @throws Exception */ @Test public void testAsynchronousChunkedBatchWithCompletionPolicy() throws Exception { @@ -113,8 +110,6 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests { /** * Explicit chunking of input data. Transactions would be laid on at the * level of template.execute(). - * - * @throws Exception */ @Test public void testChunksWithTruncatedItemProvider() throws Exception { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SimpleMethodInvokerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SimpleMethodInvokerTests.java index 39ed0d124..434a12978 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SimpleMethodInvokerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SimpleMethodInvokerTests.java @@ -31,16 +31,17 @@ */ package org.springframework.batch.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.lang.reflect.Method; import org.junit.Before; import org.junit.Test; + import org.springframework.util.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Lucas Ward * @@ -137,7 +138,7 @@ public class SimpleMethodInvokerTests { } public void argumentTest(Object object){ - Assert.notNull(object); + Assert.notNull(object, "Object must not be null"); argumentTestCalled = true; } } diff --git a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index 61409abd8..11f7e6a73 100644 --- a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -114,7 +114,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource); + Assert.notNull(dataSource, "A DataSource is required"); initialize(); } diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemWriter.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemWriter.java index 743b75591..2065db34b 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemWriter.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemWriter.java @@ -56,7 +56,7 @@ public class AsyncItemWriter implements ItemStreamWriter>, Initiali * unwrapped and the cause will be thrown. * * @param items {@link java.util.concurrent.Future}s to be upwrapped and passed to the delegate - * @throws Exception + * @throws Exception The exception returned by the Future if one was thrown */ public void write(List> items) throws Exception { List list = new ArrayList(); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java index 05e9d06b2..009bb7fb8 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java @@ -1,14 +1,12 @@ package org.springframework.batch.integration.chunk; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.util.Arrays; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; @@ -42,6 +40,9 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StringUtils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class ChunkMessageItemWriterIntegrationTests { @@ -186,11 +187,6 @@ public class ChunkMessageItemWriterIntegrationTests { } - /** - * @param jobId - * @param string - * @return - */ @SuppressWarnings({"unchecked", "rawtypes"}) private GenericMessage getSimpleMessage(String string, Long jobId) { StepContribution stepContribution = new JobExecution(new JobInstance(0L, "job"), new JobParameters()) @@ -262,8 +258,6 @@ public class ChunkMessageItemWriterIntegrationTests { /** * This one is flakey - we try to force it to wait until after the step to * finish processing just by waiting for long enough. - * - * @throws Exception */ @Test public void testFailureInStepListener() throws Exception { @@ -294,11 +288,6 @@ public class ChunkMessageItemWriterIntegrationTests { // TODO : test non-dispatch of empty chunk - /** - * @param expected - * @param maxWait - * @throws InterruptedException - */ private void waitForResults(int expected, int maxWait) throws InterruptedException { int count = 0; while (TestItemWriter.count < expected && count < maxWait) { diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/RemoteChunkingParserTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/RemoteChunkingParserTests.java index 77e46fda2..4c6b58206 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/RemoteChunkingParserTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/RemoteChunkingParserTests.java @@ -15,7 +15,10 @@ */ package org.springframework.batch.integration.config.xml; +import java.util.List; + import org.junit.Test; + import org.springframework.batch.core.step.item.ChunkProcessor; import org.springframework.batch.core.step.item.SimpleChunkProcessor; import org.springframework.batch.integration.chunk.ChunkHandler; @@ -32,7 +35,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.config.ServiceActivatorFactoryBean; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.MessageChannel; -import java.util.List; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -47,7 +49,10 @@ import static org.junit.Assert.fail; * @author Chris Schaefer * @since 3.1 */ +@SuppressWarnings("unchecked") public class RemoteChunkingParserTests { + + @SuppressWarnings("rawtypes") @Test public void testRemoteChunkingSlaveParserWithProcessorDefined() { ApplicationContext applicationContext = @@ -80,6 +85,7 @@ public class RemoteChunkingParserTests { assertNotNull("Target object must not be null", targetObject); } + @SuppressWarnings("rawtypes") @Test public void testRemoteChunkingSlaveParserWithProcessorNotDefined() { ApplicationContext applicationContext = @@ -94,6 +100,7 @@ public class RemoteChunkingParserTests { assertTrue("Got wrong instance of ItemProcessor", itemProcessor instanceof PassThroughItemProcessor); } + @SuppressWarnings("rawtypes") @Test public void testRemoteChunkingMasterParser() { ApplicationContext applicationContext = @@ -103,7 +110,7 @@ public class RemoteChunkingParserTests { assertNotNull("Messaging template must not be null", TestUtils.getPropertyValue(itemWriter, "messagingGateway")); assertNotNull("Reply channel must not be null", TestUtils.getPropertyValue(itemWriter, "replyChannel")); - FactoryBean remoteChunkingHandlerFactoryBean = applicationContext.getBean(RemoteChunkHandlerFactoryBean.class); + FactoryBean remoteChunkingHandlerFactoryBean = applicationContext.getBean(RemoteChunkHandlerFactoryBean.class); assertNotNull("Chunk writer must not be null", TestUtils.getPropertyValue(remoteChunkingHandlerFactoryBean, "chunkWriter")); assertNotNull("Step must not be null", TestUtils.getPropertyValue(remoteChunkingHandlerFactoryBean, "step")); } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandlerTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandlerTests.java index 9dca70fab..59ed868ea 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandlerTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandlerTests.java @@ -54,6 +54,7 @@ public class MessageChannelPartitionHandlerTests { assertNull(executions); } + @SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testHandleNoReply() throws Exception { //execute with no default set @@ -79,6 +80,7 @@ public class MessageChannelPartitionHandlerTests { assertTrue(executions.isEmpty()); } + @SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testHandleWithReplyChannel() throws Exception { //execute with no default set @@ -107,6 +109,7 @@ public class MessageChannelPartitionHandlerTests { } + @SuppressWarnings("rawtypes") @Test(expected = MessageTimeoutException.class) public void messageReceiveTimeout() throws Exception { //execute with no default set diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/mail/internal/TestMailSender.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/mail/internal/TestMailSender.java index badef2cb3..62ca4e884 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/mail/internal/TestMailSender.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/mail/internal/TestMailSender.java @@ -35,9 +35,9 @@ import org.springframework.mail.SimpleMailMessage; */ public class TestMailSender implements MailSender { - private List subjectsToFail = new ArrayList(); + private List subjectsToFail = new ArrayList<>(); - private List received = new ArrayList(); + private List received = new ArrayList<>(); public void clear() { received.clear(); @@ -53,8 +53,8 @@ public class TestMailSender implements MailSender { } @Override - public void send(SimpleMailMessage[] simpleMessages) throws MailException { - Map failedMessages = new LinkedHashMap(); + public void send(SimpleMailMessage... simpleMessages) throws MailException { + Map failedMessages = new LinkedHashMap<>(); for (SimpleMailMessage simpleMessage : simpleMessages) { if (subjectsToFail.contains(simpleMessage.getSubject())) { failedMessages.put(simpleMessage, new MessagingException()); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/TradeWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/TradeWriter.java index effef0380..ae0922ed0 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/TradeWriter.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/TradeWriter.java @@ -56,7 +56,7 @@ public class TradeWriter extends ItemStreamSupport implements ItemWriter dao.writeTrade(trade); - Assert.notNull(trade.getPrice()); // There must be a price to total + Assert.notNull(trade.getPrice(), "price must not be null"); // There must be a price to total if (this.failingCustomers.contains(trade.getCustomer())) { throw new WriteFailedException("Something unexpected happened!"); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemReader.java index d434de484..62c78b805 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemReader.java @@ -15,12 +15,12 @@ */ package org.springframework.batch.sample.jsr352; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.batch.api.chunk.AbstractItemReader; import java.util.ArrayList; import java.util.List; +import javax.batch.api.chunk.AbstractItemReader; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** *

@@ -30,6 +30,7 @@ import java.util.List; * @since 3.0 * @author Chris Schaefer */ +@SuppressWarnings("serial") public class JsrSampleItemReader extends AbstractItemReader { private static final Log LOG = LogFactory.getLog(JsrSampleItemReader.class); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/HeaderCopyCallback.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/HeaderCopyCallback.java index 84c2b699f..8a59ba169 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/HeaderCopyCallback.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/HeaderCopyCallback.java @@ -33,7 +33,7 @@ public class HeaderCopyCallback implements LineCallbackHandler, FlatFileHeaderCa @Override public void handleLine(String line) { - Assert.notNull(line); + Assert.notNull(line, "line must not be null"); this.header = line; } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractFieldSetMapperTests.java index d975359a1..b8d63bcac 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/AbstractFieldSetMapperTests.java @@ -15,12 +15,13 @@ */ package org.springframework.batch.sample.support; -import static org.junit.Assert.assertEquals; - import org.junit.Test; + import org.springframework.batch.item.file.mapping.FieldSetMapper; import org.springframework.batch.item.file.transform.FieldSet; +import static org.junit.Assert.assertEquals; + /** * Encapsulates basic logic for testing custom {@link FieldSetMapper} implementations. * @@ -49,7 +50,6 @@ public abstract class AbstractFieldSetMapperTests { /** * Regular usage scenario. * Assumes the domain object implements sensible equals(Object other) - * @throws Exception */ @Test public void testRegularUse() throws Exception { diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/AbstractJobTests.java b/spring-batch-test/src/main/java/org/springframework/batch/test/AbstractJobTests.java index da62e07af..e987fc8c0 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/AbstractJobTests.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/AbstractJobTests.java @@ -126,7 +126,6 @@ public abstract class AbstractJobTests implements ApplicationContextAware { * Launch the entire job, including all steps. * * @return JobExecution, so that the test can validate the exit status - * @throws Exception */ protected JobExecution launchJob() throws Exception { return this.launchJob(this.getUniqueJobParameters()); @@ -135,9 +134,8 @@ public abstract class AbstractJobTests implements ApplicationContextAware { /** * Launch the entire job, including all steps * - * @param jobParameters + * @param jobParameters parameters for the job * @return JobExecution, so that the test can validate the exit status - * @throws Exception */ protected JobExecution launchJob(JobParameters jobParameters) throws Exception { return getJobLauncher().run(this.job, jobParameters); diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java b/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java index bfd90266c..a1b42dfc6 100755 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java @@ -98,7 +98,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource); + Assert.notNull(dataSource, "A DataSource is required"); initialize(); }