diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestExecutionListener.java b/spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestExecutionListener.java index e7855637c..e29854156 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestExecutionListener.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestExecutionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2010 the original author or authors. + * Copyright 2006-2023 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. @@ -104,7 +104,7 @@ public class JobScopeTestExecutionListener implements TestExecutionListener { @Override public void afterTestMethod(TestContext testContext) throws Exception { if (testContext.hasAttribute(JOB_EXECUTION)) { - JobSynchronizationManager.close(); + JobSynchronizationManager.release(); } } diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestUtils.java b/spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestUtils.java index 6c54e35da..af0f7b70e 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestUtils.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2010 the original author or authors. + * Copyright 2006-2023 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. @@ -29,6 +29,7 @@ import org.springframework.batch.core.scope.context.JobSynchronizationManager; * * @author Dave Syer * @author Jimmy Praet + * @author Mahmoud Ben Hassine */ public class JobScopeTestUtils { @@ -38,7 +39,7 @@ public class JobScopeTestUtils { return callable.call(); } finally { - JobSynchronizationManager.close(); + JobSynchronizationManager.release(); } } diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/JobScopeTestExecutionListenerIntegrationTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/JobScopeTestExecutionListenerIntegrationTests.java index 2eea7c3c9..ff1aacc78 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/JobScopeTestExecutionListenerIntegrationTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/JobScopeTestExecutionListenerIntegrationTests.java @@ -1,64 +1,67 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://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. - */ -package org.springframework.batch.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.ItemStream; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; - -/** - * @author Dave Syer - * @author Mahmoud Ben Hassine - * @since 2.1 - */ -@ContextConfiguration -@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class }) -@RunWith(SpringJUnit4ClassRunner.class) -public class JobScopeTestExecutionListenerIntegrationTests { - - @Autowired - private ItemReader reader; - - @Autowired - private ItemStream stream; - - public JobExecution getJobExecution() { - // Assert that dependencies are already injected... - assertNotNull(reader); - // Then create the execution for the job scope... - JobExecution execution = MetaDataInstanceFactory.createJobExecution(); - execution.getExecutionContext().putString("input.file", "classpath:/org/springframework/batch/test/simple.txt"); - return execution; - } - - @Test - public void testJob() throws Exception { - stream.open(new ExecutionContext()); - assertEquals("foo", reader.read()); - } - -} +/* + * Copyright 2013-2023 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 + * + * https://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. + */ +package org.springframework.batch.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.item.ExecutionContext; +import org.springframework.batch.item.ItemReader; +import org.springframework.batch.item.ItemStream; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestExecutionListeners; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; + +/** + * @author Dave Syer + * @author Mahmoud Ben Hassine + * @since 2.1 + */ +@ContextConfiguration +@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class }) +@RunWith(SpringJUnit4ClassRunner.class) +public class JobScopeTestExecutionListenerIntegrationTests { + + @Autowired + private ItemReader reader; + + @Autowired + private ItemStream stream; + + public JobExecution getJobExecution() { + // Assert that dependencies are already injected... + assertNotNull(reader); + // Then create the execution for the job scope... + JobExecution execution = MetaDataInstanceFactory.createJobExecution(); + execution.getExecutionContext().putString("input.file", "classpath:/org/springframework/batch/test/simple.txt"); + return execution; + } + + @Test + public void testJob() throws Exception { + stream.open(new ExecutionContext()); + assertEquals("foo", reader.read()); + assertEquals("bar", reader.read()); + assertNull(reader.read()); + } + +}