title: Spring Batch: unit test late binding
body: <p>I have reader configured as below:</p>
  
  <pre><code>&lt;bean name="reader" class="...Reader" scope="step"&gt;
      &lt;property name="from" value="#{jobParameters[from]}" /&gt;
      &lt;property name="to" value="#{jobParameters[to]}" /&gt;
      &lt;property name="pageSize" value="5"/&gt;
      &lt;property name="saveState" value="false" /&gt; &lt;!-- we use a database flag to indicate processed records --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>and a test for it like this:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration({"classpath:testApplicationContext.xml"})
  @ActiveProfiles({"default","mock"})
  @TestExecutionListeners( {StepScopeTestExecutionListener.class })
  public class TestLeadsReader extends    AbstractTransactionalJUnit4SpringContextTests {
  
  @Autowired
  private ItemStreamReader&lt;Object[]&gt; reader;
  
  public StepExecution getStepExecution() {
      StepExecution execution = MetaDataInstanceFactory.createStepExecution();
      execution.getExecutionContext().putLong("campaignId", 1);
      execution.getExecutionContext().putLong("partnerId", 1);
  
      Calendar.getInstance().set(2015, 01, 20, 17, 12, 00);
      execution.getExecutionContext().put("from", Calendar.getInstance().getTime());
      Calendar.getInstance().set(2015, 01, 21, 17, 12, 00);
      execution.getExecutionContext().put("to", Calendar.getInstance().getTime());
      return execution;
  }
  
  @Test
  public void testMapper() throws Exception {
      for (int i = 0; i &lt; 10; i++) {
          assertNotNull(reader.read());
      }
      assertNull(reader.read());
  }
  </code></pre>
  
  <p>Now, although the pageSize and saveState are injected correctly into my reader, the job parameters are not. According to the documentation this is all that it needs to be done and the only issues I found were about using jobParameters['from'] instead of jobParameters[from]. Any idea what could be wrong?</p>
  
  <p>Also, the open(executionContext) method is not called on my reader before it enters the test method, which is not ok, because I use those job parameters to retrieve some data that needs to be available when the read method is called. This might be related to the above problem though, because the documentation concerning testing with late binding says that "The reader is initialized and bound to the input data".</p>