### Question:
EcLogYamlConfig { public Optional<DateTimeFormatter> getTimeFormatter() { return Optional.ofNullable(time_format) .map(EcLogYamlConfig::createTimeFormatter) .map(formatter -> formatter.withZone(resolveZoneId(time_zone))); }  String getLogFormat(); Optional<DateTimeFormatter> getTimeFormatter(); public String log_format; public String time_format; public String time_zone; }### Answer:
@Test public void testCustomTimeFormatterWithDefaultZone() { EcLogYamlConfig config = new EcLogYamlConfig(); config.time_format = TIME_FORMAT; Optional<DateTimeFormatter> timeFormatter = config.getTimeFormatter(); assertThat(timeFormatter).map(DateTimeFormatter::getZone).contains(ZoneId.systemDefault()); }
@Test public void testCustomTimeFormatterWithCustomZone() { EcLogYamlConfig config = new EcLogYamlConfig(); config.time_format = TIME_FORMAT; config.time_zone = "Europe/Stockholm"; Optional<DateTimeFormatter> timeFormatter = config.getTimeFormatter(); assertThat(timeFormatter).map(DateTimeFormatter::getZone).contains(ZoneId.of(config.time_zone)); assertThat(timeFormatter).map(formatter -> formatter.format(Instant.ofEpochSecond(42))).contains("1970-01-01 01:00:42 CET+0100"); }
@Test public void testDefaultTimeFormatter() { EcLogYamlConfig defaultConfig = new EcLogYamlConfig(); assertThat(defaultConfig.getTimeFormatter()).isEmpty(); }