DateUtils { public DateTimeFormatter getDateTimeFormatter(String pattern) { try { return DateTimeFormatter.ofPattern(pattern); } catch (Exception e) { return getDateTimeFormatter(DEFAULT_FORMAT_PATTERN); } } @Autowired  DateUtils(SettingsAware settingsAware); String formatDate(ZonedDateTime date); DateTimeFormatter getDateTimeFormatter(String pattern);  }
@Test public void testInvalidDateTimePattern() { DateTimeFormatter invalidPatternDateTimeFormatter = dateUtils.getDateTimeFormatter("invalid"); DateTimeFormatter defaultDateTimeFormatter = DateTimeFormatter.ofPattern("YYYYMMdd_HHmmss"); ZonedDateTime dateTime = ZonedDateTime.now(); assertThat(invalidPatternDateTimeFormatter.format(dateTime), equalTo(defaultDateTimeFormatter.format(dateTime))); }