MoveFileTasklet implements Tasklet, InitializingBean { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { Path sourcePath = source.getFile().toPath(); if (destination != null) { Path destinationPath = destination.getFile().toPath(); Path directoryPath; if (Files.isDirectory(destinationPath)) { directoryPath = destinationPath; destinationPath = directoryPath.resolve(sourcePath.getFileName()); } else { directoryPath = destinationPath.getParent(); } Files.createDirectories(directoryPath); destinationPath = Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING); contribution.incrementWriteCount(1); LOGGER.debug("Moved file to {}", destinationPath); } if (Files.deleteIfExists(sourcePath)) { LOGGER.info("Deleted file {}", sourcePath); } return RepeatStatus.FINISHED; }  @Override void afterPropertiesSet(); @Override RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext); void setSource(Resource source); void setDestination(Resource destination);  }
@Test public void testMove() throws Exception { Assert.assertEquals(1, getExcelFiles().length); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(); StepContribution stepContribution = new StepContribution(stepExecution); ChunkContext chunkContext = new ChunkContext(new StepContext(stepExecution)); RepeatStatus repeatStatus = tasklet.execute(stepContribution, chunkContext); Assert.assertEquals(RepeatStatus.FINISHED, repeatStatus); Assert.assertEquals(0, getExcelFiles().length); Assert.assertEquals(1, stepContribution.getWriteCount()); }