DateUtils { public String formatDate(ZonedDateTime date) { return getDateTimeFormatter(getFormatPattern()).format(date); } @Autowired  DateUtils(SettingsAware settingsAware); String formatDate(ZonedDateTime date); DateTimeFormatter getDateTimeFormatter(String pattern);  }
@Test public void testFormatDate() { ZonedDateTime zonedDateTime = ZonedDateTime.of(2016, 2, 1, 10, 5, 20, 0, ZoneId.systemDefault()); assertThat(dateUtils.formatDate(zonedDateTime), equalTo("20160201_100520")); settingsAware.setSetting(Setting.DATE_FORMAT, Collections.singleton("YYYYMMdd")); assertThat(dateUtils.formatDate(zonedDateTime), equalTo("20160201")); }