SharedUtilities { public static int calculateAge(Date birthDate) { if (birthDate == null) { throw new NullPointerException("birthDate cannot be null"); } LocalDate localBirthDate = birthDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); return Period.between(localBirthDate, LocalDate.now()).getYears(); }  static int calculateAge(Date birthDate);  }
@Test public void testCalculateAge() { LocalDate birthDate = LocalDate.now().minus(40, ChronoUnit.YEARS); int age = SharedUtilities .calculateAge(Date.from(birthDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); assertEquals(40, age); }