BatchExcelRowMapper implements RowMapper<BatchExcelRow>, InitializingBean { @Override public BatchExcelRow mapRow(Row row, int rowIndex) throws RowMappingException { try { return new BatchExcelRow.Builder(getDate(row, DATE_INDEX), null) .departureStation(getStation(row, DEPARTURE_STATION_INDEX)) .arrivalStation(getStation(row, ARRIVAL_STATION_INDEX)) .linkStation(getStation(row, LINK_STATION_INDEX)) .expectedDepartureTime(getHHMM(row, EXPECTED_DEPARTURE_HH_INDEX, EXPECTED_DEPARTURE_MM_INDEX)) .expectedArrivalTime(getHHMM(row, EXPECTED_ARRIVAL_HH_INDEX, EXPECTED_ARRIVAL_MM_INDEX)) .expectedTrain1(getTrain(row, EXPECTED_TRAIN1_INDEX)) .expectedTrain2(getTrain(row, EXPECTED_TRAIN2_INDEX)) .effectiveDepartureTime(getHHMM(row, EFFECTIVE_DEPARTURE_HH_INDEX, EFFECTIVE_DEPARTURE_MM_INDEX)) .effectiveArrivalTime(getHHMM(row, EFFECTIVE_ARRIVAL_HH_INDEX, EFFECTIVE_ARRIVAL_MM_INDEX)) .effectiveTrain1(getTrain(row, EFFECTIVE_TRAIN1_INDEX)) .effectiveTrain2(getTrain(row, EFFECTIVE_TRAIN2_INDEX)) .delay(getLong(row, DELAY_INDEX)) .index((long) row.getRowNum()) .build(validateOutcomes); } catch (ValidationException e) { throw new RowMappingException(e, row, rowIndex); } }  @Override void afterPropertiesSet(); @Override BatchExcelRow mapRow(Row row, int rowIndex); void setLanguage(String language); @SuppressWarnings("unused") void setValidateOutcomes(boolean validateOutcomes); static final int DATE_INDEX; static final int DEPARTURE_STATION_INDEX; static final int ARRIVAL_STATION_INDEX; static final int LINK_STATION_INDEX; static final int EXPECTED_DEPARTURE_HH_INDEX; static final int EXPECTED_DEPARTURE_MM_INDEX; static final int EFFECTIVE_TRAIN1_INDEX; static final int EFFECTIVE_TRAIN2_INDEX; static final int DELAY_INDEX; static final int EXPECTED_TRAIN1_INDEX; static final int EXPECTED_TRAIN2_INDEX; static final int EXPECTED_ARRIVAL_HH_INDEX; static final int EXPECTED_ARRIVAL_MM_INDEX; static final int EFFECTIVE_DEPARTURE_HH_INDEX; static final int EFFECTIVE_DEPARTURE_MM_INDEX; static final int EFFECTIVE_ARRIVAL_HH_INDEX; static final int EFFECTIVE_ARRIVAL_MM_INDEX; }
@Test public void testMapRow() throws Exception { NumberFormat format = new DecimalFormat("#"); BatchExcelRow batchExcelRow = mapper.mapRow(row, 0); Assert.assertNotNull(batchExcelRow); Assert.assertEquals(DELAY, batchExcelRow.getDelay().longValue()); Assert.assertEquals(format.format(TRAIN1), batchExcelRow.getEffectiveTrainLine1().getName()); }
@Test public void testRoundTrip() throws Exception { BatchExcelRow expected = new BatchExcelRow.Builder(LocalDate.parse("2000-01-01"), null) .departureStation(new Station("BRUXELLES-CENTRAL")) .arrivalStation(new Station("LIEGE-GUILLEMINS")) .expectedDepartureTime(LocalTime.parse("14:00")) .expectedArrivalTime(LocalTime.parse("15:00")) .expectedTrain1(new TrainLine.Builder(529L).build()) .expectedTrain2(new TrainLine.Builder(516L).build()) .effectiveDepartureTime(LocalTime.parse("14:05")) .effectiveArrivalTime(LocalTime.parse("15:15")) .effectiveTrain1(new TrainLine.Builder(529L).build()) .effectiveTrain2(new TrainLine.Builder(516L).build()) .delay(10L) .build(); ExcelRow previousRow = new ExcelRowAggregator().aggregate(expected, workbook, SHEET_INDEX, ROW_INDEX); BatchExcelRow batchExcelRow = mapper.mapRow(workbook.getSheetAt(SHEET_INDEX).getRow(ROW_INDEX), ROW_INDEX); Assert.assertNotNull(previousRow); Assert.assertNotEquals(expected, previousRow); Assert.assertNotNull(batchExcelRow); Assert.assertNotEquals(batchExcelRow, previousRow); Assert.assertEquals(expected, batchExcelRow); }