AggregateExpectedTimeProcessor implements ItemProcessor<LineStop, LineStop> { @Override public LineStop process(LineStop item) throws Exception { LineStop result = item; LOGGER.trace("item", item); if (hasAnyCanceled(item)) { LOGGER.info("have_canceled_stop", item); LineStop.Builder builder = fetchScheduling(item); if (builder != null) { LineStop previous = item.getPrevious(); while (previous != null) { builder.addPrevious(fetchScheduling(previous)); previous = previous.getPrevious(); } LineStop next = item.getNext(); while (next != null) { builder.addNext(fetchScheduling(next)); next = next.getNext(); } result = builder.build(); LOGGER.debug("after_processing", result); } } LOGGER.trace("result", result); return result; }  @Override LineStop process(LineStop item); LineStop.Builder fetchScheduling(LineStop item); void setLineStopDao(LineStopDao lineStopDao);  }
@Test public void testProcess() throws Exception { EasyMock.expect(lineStopDao.findFistScheduledLine(TRAIN_LINE, DEPARTURE_STATION)) .andReturn(expected.getPrevious()); EasyMock.expect(lineStopDao.findFistScheduledLine(TRAIN_LINE, INTERMEDIATE_STATION)) .andReturn(expected); EasyMock.expect(lineStopDao.findFistScheduledLine(TRAIN_LINE, ARRIVAL_STATION)) .andReturn(expected.getNext()); replayAll(); LineStop result = processor.process(item); Assert.assertNotNull(result); Assert.assertEquals(LocalTime.parse("17:00"), result.getPrevious().getArrivalTime().getExpectedTime()); Assert.assertEquals(LocalTime.parse("17:01"), result.getPrevious().getDepartureTime().getExpectedTime()); Assert.assertEquals(LocalTime.parse("18:20"), result.getArrivalTime().getExpectedTime()); Assert.assertEquals(LocalTime.parse("18:21"), result.getDepartureTime().getExpectedTime()); Assert.assertEquals(LocalTime.parse("18:30"), result.getNext().getArrivalTime().getExpectedTime()); Assert.assertEquals(LocalTime.parse("18:31"), result.getNext().getDepartureTime().getExpectedTime()); verifyAll(); }
@Test public void testProcessNoCandidate() throws Exception { EasyMock.expect(lineStopDao.findFistScheduledLine(TRAIN_LINE, DEPARTURE_STATION)) .andReturn(null); EasyMock.expect(lineStopDao.findFistScheduledLine(TRAIN_LINE, INTERMEDIATE_STATION)) .andReturn(null); EasyMock.expect(lineStopDao.findFistScheduledLine(TRAIN_LINE, ARRIVAL_STATION)) .andReturn(null); replayAll(); LineStop result = processor.process(item); Assert.assertNotNull(result); Assert.assertEquals(item, result); }