LimsFactory { @NotNull @VisibleForTesting static Map<String, LocalDate> readPreLimsArrivalDateTsv(@NotNull String preLimsArrivalDatesTsv) throws IOException { Map<String, LocalDate> arrivalDatesPerSampleId = Maps.newHashMap(); List<String> lines = Files.lines(Paths.get(preLimsArrivalDatesTsv)).collect(Collectors.toList()); for (String line : lines) { String[] parts = line.split(FIELD_SEPARATOR); if (parts.length == 2) { String sampleId = parts[0].trim(); String arrivalDateString = parts[1].trim(); LocalDate arrivalDate; try { arrivalDate = LocalDate.parse(arrivalDateString, LimsConstants.DATE_FORMATTER); } catch (DateTimeParseException exc) { LOGGER.warn("Could not parse date in pre-HMF arrival date csv: {}", arrivalDateString); arrivalDate = null; } arrivalDatesPerSampleId.put(sampleId, arrivalDate); } else { LOGGER.warn("Invalid line in pre-HMF arrival date csv: {}", line); } } return arrivalDatesPerSampleId; } private  LimsFactory(); @NotNull static Lims fromLimsDirectory(@NotNull String limsDirectory); @NotNull static Lims empty();  }
@Test public void readCorrectlyFromPreLimsArrivalDateFile() throws IOException { Map<String, LocalDate> preLimsArrivalDates = LimsFactory.readPreLimsArrivalDateTsv(LIMS_DIRECTORY + File.separator + "pre_lims_arrival_dates.tsv"); assertNull(preLimsArrivalDates.get("SAMP01010001T")); assertEquals(LimsTestUtil.toDate("2017-01-01"), preLimsArrivalDates.get("SAMP01010003R")); assertEquals(LimsTestUtil.toDate("2017-01-05"), preLimsArrivalDates.get("SAMP01010004T")); assertNull(preLimsArrivalDates.get("SAMP01010005T")); assertNull(preLimsArrivalDates.get("SAMP01010006R")); assertNull(preLimsArrivalDates.get("DoesNotExist")); }