LocalDateToIntConverter { public static int convertToInt(LocalDate date) { int year = date.getYear(); int month = date.getMonthValue(); int day = date.getDayOfMonth(); if (year > 9999) { if (date.equals(LocalDate.MAX)) { return Integer.MAX_VALUE; } throw new IllegalArgumentException("LocalDate has year > 9999"); } if (year < 0) { if (date.equals(LocalDate.MIN)) { return Integer.MIN_VALUE; } throw new IllegalArgumentException("LocalDate has year < 0"); } return year * 10000 + month * 100 + day; } private  LocalDateToIntConverter(); static int convertToInt(LocalDate date); static LocalDate convertToLocalDate(int date); static void checkValid(int date);  }
@Test(dataProvider = "conversions") public void test_convertToInt(LocalDate input, int expected) { assertEquals(LocalDateToIntConverter.convertToInt(input), expected); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_convertToLocalDate_tooBig() { LocalDateToIntConverter.convertToInt(LocalDate.of(10_000, 1, 1)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_convertToLocalDate_tooSmall() { LocalDateToIntConverter.convertToInt(LocalDate.of(-1, 1, 1)); }