@Test public void testWithJobExecutionFactory() throws Exception { testExecutionContext(new WithJobExecutionFactory()); }
@Test public void testWithParameters() throws Exception { testJobParameters(new WithJobExecutionFactory()); }
@Test public void testDefaultJobContext() throws Exception { TestContext testContext = getTestContext(new Object()); listener.prepareTestInstance(testContext); listener.beforeTestMethod(testContext); JobContext context = JobSynchronizationManager.getContext(); assertNotNull(context); listener.afterTestMethod(testContext); assertNull(JobSynchronizationManager.getContext()); }
private void testExecutionContext(Object target) throws Exception { TestContext testContext = getTestContext(target); listener.prepareTestInstance(testContext); try { listener.beforeTestMethod(testContext); JobContext context = JobSynchronizationManager.getContext(); assertNotNull(context); assertEquals("bar", context.getJobExecutionContext().get("foo")); } finally { listener.afterTestMethod(testContext); } assertNull(JobSynchronizationManager.getContext()); }
private void testJobParameters(Object target) throws Exception { TestContext testContext = getTestContext(target); listener.prepareTestInstance(testContext); try { listener.beforeTestMethod(testContext); JobContext context = JobSynchronizationManager.getContext(); assertNotNull(context); assertEquals("spam", context.getJobParameters().get("foo")); } finally { listener.afterTestMethod(testContext); } assertNull(JobSynchronizationManager.getContext()); }