ExcelRowToWriteResourceLocator extends CountingItemResourceLocator<ExcelRow> { @Override public void onWrite(ExcelRow item, ResourceContext context) throws Exception { super.onWrite(item, context); if (!context.containsResource() && isValid(item)) { String suffix = item.getDate().format(DateTimeFormatter.ofPattern("yyyyMMdd")); File file = ExcelFileUtils.getFile(new File(directoryPath), fileName, suffix, fileExtension); context.changeResource(new FileSystemResource(file)); } }  @Override void onWrite(ExcelRow item, ResourceContext context); void setFileName(String fileName); void setFileExtension(String fileExtension); void setDirectoryPath(String directoryPath);  }
@Test public void testOnWrite() throws Exception { ExcelRow item = new ExcelRow .Builder(LocalDate.of(2000, 1, 1), Sens.ARRIVAL) .build(false); resourceLocator.onWrite(item, context); Assert.assertEquals("." + File.separator + "retard_sncb 20000101.xls", context.consumeResource().getFile().getPath()); }
@Test public void testOnWriteNoItems() throws Exception { resourceLocator.onWrite(null, context); Assert.assertNull(context.consumeResource()); }