LogSkippedItemListener implements SkipListener<Object, BatchExcelRow>, ItemProcessListener<Object, Object> { @Override public void onSkipInProcess(Object item, Throwable t) { if (item instanceof LineStop) { PROCESS.info(t.getMessage(), (LineStop) item); } else if (item instanceof ExcelRow) { PROCESS.info(t.getMessage(), (ExcelRow) item); } else { PROCESS.info("unknown_type", (ExcelRow) null); PROCESS.debug(t.getMessage(), (ExcelRow) null); } }  @Override void onSkipInRead(Throwable t); @Override void onSkipInWrite(BatchExcelRow item, Throwable t); @Override void onSkipInProcess(Object item, Throwable t); @Override void beforeProcess(Object item); @Override void afterProcess(Object item, Object result); @Override void onProcessError(Object item, Exception e);  }
@Test public void testOnSkipInProcessExcelRow() throws Exception { listener.onSkipInProcess(new ExcelRow .Builder(LocalDate.now(), Sens.DEPARTURE) .departureStation(new Station("foo")) .arrivalStation(new Station("bar")) .expectedDepartureTime(LocalTime.parse("15:00")) .expectedArrivalTime(LocalTime.parse("16:00")) .build(false), new Exception("error") ); Assert.assertTrue(appender.getEvents() .stream() .anyMatch(logEvent -> { String formattedMessage = logEvent .getMessage() .getFormattedMessage(); return formattedMessage.contains("foo") && formattedMessage.contains("bar") && formattedMessage.contains("15:00 16:00") && formattedMessage.contains("error"); })); }
@Test public void testOnSkipInProcessLineStop() throws Exception { listener.onSkipInProcess(new LineStop .Builder() .date(LocalDate.now()) .station(new Station("foo")) .trainLine(new TrainLine.Builder(466L).build()) .departureTime(TimeDelay.of(LocalTime.parse("15:00"))) .arrivalTime(TimeDelay.of(LocalTime.parse("16:00"))) .build(), new Exception("error") ); Assert.assertTrue(appender.getEvents() .stream() .anyMatch(logEvent -> { String formattedMessage = logEvent .getMessage() .getFormattedMessage(); return formattedMessage.contains("foo") && formattedMessage.contains("15:00 16:00") && formattedMessage.contains("error"); })); }
@Test public void testOnSkipInProcessUnknownType() throws Exception { listener.onSkipInProcess(new Object(), new Exception("error") ); Assert.assertTrue(appender.getEvents() .stream() .anyMatch(logEvent -> logEvent .getMessage() .getFormattedMessage() .contains("error") )); }