AbstractResourceLocatorItemStream extends ItemStreamSupport implements ResourceContextAccessibleItemStream { @Override public void open(ExecutionContext executionContext) throws ItemStreamException { resourceContext = new ResourceContext( executionContext, getExecutionContextKey(this.getClass().getSimpleName()) ); resourceLocator.onOpen(resourceContext); if (delegate instanceof AbstractItemCountingItemStreamItemWriter) { ((AbstractItemCountingItemStreamItemWriter) delegate).setCurrentItemIndex( resourceContext.getCurrentIndex() ); } if (resourceContext.containsResource()) { delegate.setResource(resourceContext.getResource()); delegate.open(executionContext); opened = true; } }  @Override void open(ExecutionContext executionContext); @Override void close(); void setDelegate(S delegate); void setResourceLocator(ResourceLocator<T> resourceLocator); @Override ResourceContext getResourceContext(); @Override void setResource(Resource resource);  }
@Test public void testOpen() throws Exception { ExecutionContext executionContext = new ExecutionContext(); executionContext.put(KEY, "foo"); delegator.setResourceLocator(new CountingItemResourceLocator<String>() { @Override public void onOpen(ResourceContext context) throws ItemStreamException { context.changeResource(new FileSystemResource(executionContext.getString(KEY))); } }); delegator.open(executionContext); Assert.assertEquals("foo", delegate.getResource().getFile().getPath()); }