BoundaryPointXlsParser { public Map<String, BoundaryPoint> parse(InputStream is) throws IOException { Map<String, BoundaryPoint> boundaryPoints = new HashMap<>(); HSSFWorkbook workbook = new HSSFWorkbook(is); HSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); rowIterator.next(); rowIterator.next(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); Cell boundaryPointNameCell = row.getCell(13); Cell borderFromCell = row.getCell(14); Cell borderToCell = row.getCell(15); String boundaryPointName = boundaryPointNameCell.getStringCellValue(); if (boundaryPointName.equals("-")) { continue; } Country borderFrom = toCountry(borderFromCell.getStringCellValue()); Country borderTo = toCountry(borderToCell.getStringCellValue()); boundaryPoints.put(boundaryPointName, new BoundaryPoint(boundaryPointName, borderFrom, borderTo)); } return boundaryPoints; }  Map<String, BoundaryPoint> parse(InputStream is); Map<String, BoundaryPoint> parseDefault();  }
@Test public void test() throws IOException { HSSFWorkbook workbook = createWorkbook(); byte[] buffer; try (ByteArrayOutputStream stream = new ByteArrayOutputStream(1024)) { workbook.write(stream); stream.flush(); buffer = stream.toByteArray(); } Map<String, BoundaryPoint> boundaryPoints; try (InputStream stream = new ByteArrayInputStream(buffer)) { BoundaryPointXlsParser parser = new BoundaryPointXlsParser(); boundaryPoints = parser.parse(stream); } assertEquals(1, boundaryPoints.size()); BoundaryPoint point = boundaryPoints.get("BoundaryPoint FR-BE"); assertNotNull(point); assertEquals("BoundaryPoint FR-BE", point.getName()); assertEquals(Country.FR, point.getBorderFrom()); assertEquals(Country.BE, point.getBorderTo()); }