MultiResourceToReadLocator extends CountingItemResourceLocator<T> { @Override public void onOpen(ResourceContext context) throws ItemStreamException { super.onOpen(context); try { List<Resource> result = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory.getFile().toPath(), filter)) { stream.forEach(path -> result.add(new FileSystemResource(path.toFile()))); } resources = result.toArray(new Resource[result.size()]); resourceIndex = 0; if (resources.length > 0) { context.setResource(resources[resourceIndex++]); } } catch (IOException e) { throw new ItemStreamException("I/O error when reading directory", e); } }  @Override void onOpen(ResourceContext context); @Override void onRead(T item, ResourceContext context); void setDirectory(Resource directory); void setFilter(String filter);  }
@Test public void testOnOpen() throws Exception { ResourceContext resourceContext = new ResourceContext(new ExecutionContext(), "foo"); locator.onOpen(resourceContext); Assert.assertTrue(resourceContext.containsResource()); }