@Test public void testInvalidRange() { String rangeString = "2017-01-01."; assertThatThrownBy(() -> DateRange.from(rangeString)) .isInstanceOf(InvalidDateParamException.class); }
public static DateRange from(String dateRangeParam) { if (StringUtils.isBlank(dateRangeParam)) { throw new InvalidDateParamException("Empty data range"); } String[] dateRange = dateRangeParam.split("\\.\\."); if (dateRange.length != 2) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } try { LocalDate fromDate = LocalDate.parse(dateRange[0], formatter); LocalDate toDate = LocalDate.parse(dateRange[1], formatter); if (fromDate.isAfter(toDate)) { throw new InvalidDateParamException("fromDate must be earlier than toDate"); } return new DateRange(fromDate, toDate); } catch (DateTimeParseException e) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } }
DateRange { public static DateRange from(String dateRangeParam) { if (StringUtils.isBlank(dateRangeParam)) { throw new InvalidDateParamException("Empty data range"); } String[] dateRange = dateRangeParam.split("\\.\\."); if (dateRange.length != 2) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } try { LocalDate fromDate = LocalDate.parse(dateRange[0], formatter); LocalDate toDate = LocalDate.parse(dateRange[1], formatter); if (fromDate.isAfter(toDate)) { throw new InvalidDateParamException("fromDate must be earlier than toDate"); } return new DateRange(fromDate, toDate); } catch (DateTimeParseException e) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } } }
DateRange { public static DateRange from(String dateRangeParam) { if (StringUtils.isBlank(dateRangeParam)) { throw new InvalidDateParamException("Empty data range"); } String[] dateRange = dateRangeParam.split("\\.\\."); if (dateRange.length != 2) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } try { LocalDate fromDate = LocalDate.parse(dateRange[0], formatter); LocalDate toDate = LocalDate.parse(dateRange[1], formatter); if (fromDate.isAfter(toDate)) { throw new InvalidDateParamException("fromDate must be earlier than toDate"); } return new DateRange(fromDate, toDate); } catch (DateTimeParseException e) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } } private  DateRange(@NotNull final LocalDate fromDate,
            @NotNull final LocalDate toDate); }
DateRange { public static DateRange from(String dateRangeParam) { if (StringUtils.isBlank(dateRangeParam)) { throw new InvalidDateParamException("Empty data range"); } String[] dateRange = dateRangeParam.split("\\.\\."); if (dateRange.length != 2) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } try { LocalDate fromDate = LocalDate.parse(dateRange[0], formatter); LocalDate toDate = LocalDate.parse(dateRange[1], formatter); if (fromDate.isAfter(toDate)) { throw new InvalidDateParamException("fromDate must be earlier than toDate"); } return new DateRange(fromDate, toDate); } catch (DateTimeParseException e) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } } private  DateRange(@NotNull final LocalDate fromDate,
            @NotNull final LocalDate toDate); static DateRange from(String dateRangeParam); static DateRange fromString(String dateRangeStr); Date getFromDate(); Date getToDate(); }
DateRange { public static DateRange from(String dateRangeParam) { if (StringUtils.isBlank(dateRangeParam)) { throw new InvalidDateParamException("Empty data range"); } String[] dateRange = dateRangeParam.split("\\.\\."); if (dateRange.length != 2) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } try { LocalDate fromDate = LocalDate.parse(dateRange[0], formatter); LocalDate toDate = LocalDate.parse(dateRange[1], formatter); if (fromDate.isAfter(toDate)) { throw new InvalidDateParamException("fromDate must be earlier than toDate"); } return new DateRange(fromDate, toDate); } catch (DateTimeParseException e) { throw new InvalidDateParamException( "Invalid data range: " + dateRangeParam); } } private  DateRange(@NotNull final LocalDate fromDate,
            @NotNull final LocalDate toDate); static DateRange from(String dateRangeParam); static DateRange fromString(String dateRangeStr); Date getFromDate(); Date getToDate();  }