String value
*/
- @Nullable
public String getString(String key) {
return (String) readAndValidate(key, String.class);
@@ -171,7 +170,6 @@ public class ExecutionContext implements Serializable {
* @return The String value if key is represented, specified
* default otherwise
*/
- @Nullable
public String getString(String key, String defaultString) {
if (!containsKey(key)) {
return defaultString;
diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/ExecutionContextTestUtils.java b/spring-batch-test/src/main/java/org/springframework/batch/test/ExecutionContextTestUtils.java
index a907eedae..178334421 100644
--- a/spring-batch-test/src/main/java/org/springframework/batch/test/ExecutionContextTestUtils.java
+++ b/spring-batch-test/src/main/java/org/springframework/batch/test/ExecutionContextTestUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2009 the original author or authors.
+ * Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,22 +22,26 @@ import java.util.List;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.item.ExecutionContext;
+import org.springframework.lang.Nullable;
/**
* Convenience class for accessing {@link ExecutionContext} values from job and
* step executions.
*
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
* @since 2.1.4
*
*/
public class ExecutionContextTestUtils {
@SuppressWarnings("unchecked")
+ @Nullable
public static @@ -62,6 +63,7 @@ import org.springframework.context.ApplicationContext; * @author Lucas Ward * @author Dan Garrette * @author Dave Syer + * @author Mahmoud Ben Hassine * @since 2.1 */ public class JobLauncherTestUtils { @@ -223,7 +225,7 @@ public class JobLauncherTestUtils { * loaded into the Job ExecutionContext prior to launching the step. * @return JobExecution */ - public JobExecution launchStep(String stepName, JobParameters jobParameters, ExecutionContext jobExecutionContext) { + public JobExecution launchStep(String stepName, JobParameters jobParameters, @Nullable ExecutionContext jobExecutionContext) { if (!(job instanceof StepLocator)) { throw new UnsupportedOperationException("Cannot locate step from a Job that is not a StepLocator: job=" + job.getName() + " does not implement StepLocator"); diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java b/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java index 0cf3c7fcd..ba0a0f73c 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java @@ -41,6 +41,7 @@ import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -61,7 +62,7 @@ public class JobRepositoryTestUtils extends AbstractJdbcBatchMetadataDao impleme Long count = 0L; @Override - public JobParameters getNext(JobParameters parameters) { + public JobParameters getNext(@Nullable JobParameters parameters) { return new JobParameters(Collections.singletonMap("count", new JobParameter(count++))); } diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/JsrTestUtils.java b/spring-batch-test/src/main/java/org/springframework/batch/test/JsrTestUtils.java index 34b4188d6..97d87e185 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/JsrTestUtils.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/JsrTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,11 +25,14 @@ import java.util.Date; import java.util.Properties; import java.util.concurrent.TimeoutException; +import org.springframework.lang.Nullable; + /** * Provides testing utilities to execute JSR-352 jobs and block until they are complete (since all JSR-352 based jobs * are executed asynchronously). * * @author Michael Minella + * @author Mahmoud Ben Hassine * @since 3.0 */ public class JsrTestUtils { @@ -110,6 +113,7 @@ public class JsrTestUtils { return execution; } + @Nullable public static Metric getMetric(StepExecution stepExecution, Metric.MetricType type) { Metric[] metrics = stepExecution.getMetrics(); diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java b/spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java index a529b38d3..34e7935d7 100755 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteExcep import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; import org.springframework.batch.item.ExecutionContext; +import org.springframework.lang.Nullable; /** * Utility class for executing steps outside of a {@link Job}. This is useful in @@ -61,6 +62,7 @@ import org.springframework.batch.item.ExecutionContext; * * @author Dan Garrette * @author Lucas Ward + * @author Mahmoud Ben Hassine * @since 2.0 * @see SimpleJob */ @@ -100,7 +102,7 @@ public class StepRunner { * loaded into the Job ExecutionContext prior to launching the step. * @return JobExecution */ - public JobExecution launchStep(Step step, ExecutionContext jobExecutionContext) { + public JobExecution launchStep(Step step, @Nullable ExecutionContext jobExecutionContext) { return this.launchStep(step, this.makeUniqueJobParameters(), jobExecutionContext); } @@ -126,7 +128,7 @@ public class StepRunner { * loaded into the Job ExecutionContext prior to launching the step. * @return JobExecution */ - public JobExecution launchStep(Step step, JobParameters jobParameters, final ExecutionContext jobExecutionContext) { + public JobExecution launchStep(Step step, JobParameters jobParameters, @Nullable final ExecutionContext jobExecutionContext) { // // Create a fake job // diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/context/package-info.java b/spring-batch-test/src/main/java/org/springframework/batch/test/context/package-info.java new file mode 100644 index 000000000..581392382 --- /dev/null +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/context/package-info.java @@ -0,0 +1,25 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * APIs for the configuration of Spring Batch test support. + * + * @author Mahmoud Ben Hassine + */ +@NonNullApi +package org.springframework.batch.test.context; + +import org.springframework.lang.NonNullApi; diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/package-info.java b/spring-batch-test/src/main/java/org/springframework/batch/test/package-info.java new file mode 100644 index 000000000..ffd6b2244 --- /dev/null +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/package-info.java @@ -0,0 +1,25 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Utility classes for batch job/step testing. + * + * @author Mahmoud Ben Hassine + */ +@NonNullApi +package org.springframework.batch.test; + +import org.springframework.lang.NonNullApi;