### Question:
TemporalUtils { public static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day) { try { if (year != null && month != null && day != null) { return Optional.of(LocalDate.of(year, month, day)); } if (year != null && month != null) { return Optional.of(YearMonth.of(year, month)); } if (year != null) { return Optional.of(Year.of(year)); } } catch (RuntimeException ex) { log.warn(ex.getLocalizedMessage()); } return Optional.empty(); }  static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day);  }### Answer:
@Test public void nullTest() { Integer year = null; Integer month = null; Integer day = null; Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertFalse(temporal.isPresent()); }
@Test public void nullYearTest() { Integer year = null; Integer month = 10; Integer day = 1; Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertFalse(temporal.isPresent()); }
@Test public void nullYearMonthTest() { Integer year = null; Integer month = null; Integer day = 1; Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertFalse(temporal.isPresent()); }
@Test public void yearTest() { Integer year = 2000; Integer month = null; Integer day = null; Year expected = Year.of(year); Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertTrue(temporal.isPresent()); assertEquals(expected, temporal.get()); }
@Test public void yearMonthTest() { Integer year = 2000; Integer month = 10; Integer day = null; YearMonth expected = YearMonth.of(year, month); Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertTrue(temporal.isPresent()); assertEquals(expected, temporal.get()); }
@Test public void localDateTest() { Integer year = 2000; Integer month = 10; Integer day = 10; LocalDate expected = LocalDate.of(year, month, day); Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertTrue(temporal.isPresent()); assertEquals(expected, temporal.get()); }
@Test public void monthNullTest() { Integer year = 2000; Integer month = null; Integer day = 10; Year expected = Year.of(year); Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertTrue(temporal.isPresent()); assertEquals(expected, temporal.get()); }
@Test public void wrongDayMonthTest() { Integer year = 2000; Integer month = 11; Integer day = 31; Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertFalse(temporal.isPresent()); }