@Test public void testFromXmlDefault() { TimestamperConfig config = fromXml(defaultXml()); TimestamperConfig defaultConfig = new TimestamperConfig(); assertThat( Arrays.asList(config.getSystemTimeFormat(), config.getElapsedTimeFormat()), is( Arrays.asList( defaultConfig.getSystemTimeFormat(), defaultConfig.getElapsedTimeFormat()))); }
@Test public void testFromXmlEmptyFormat() { TimestamperConfig config = fromXml(xml("", "")); assertThat( Arrays.asList(config.getSystemTimeFormat(), config.getElapsedTimeFormat()), is(Arrays.asList("", ""))); }
@Override public TimestampFormatter get() { TimestamperConfig config = GlobalConfiguration.all().get(TimestamperConfig.class); // JENKINS-16778: The request can be null when the slave goes off-line. Optional<StaplerRequest> request = Optional.fromNullable(Stapler.getCurrentRequest()); Optional<String> timeZoneId = Optional.fromNullable(System.getProperty(TIME_ZONE_PROPERTY)); return new TimestampFormatter( config.getSystemTimeFormat(), config.getElapsedTimeFormat(), request, timeZoneId); }
@Test public void testSetSystemTimeFormat() { TimestamperConfig config = new TimestamperConfig(); config.setSystemTimeFormat(customSystemTimeFormat); assertThat(config.getSystemTimeFormat(), is(customSystemTimeFormat)); }
@Test public void testFromXmlCustomSystemTimeFormat() { TimestamperConfig config = fromXml(xml(customSystemTimeFormat, null)); assertThat(config.getSystemTimeFormat(), is(customSystemTimeFormat)); }
@Test public void testSetSystemTimeFormatEmpty() { TimestamperConfig config = new TimestamperConfig(); config.setSystemTimeFormat(""); assertThat(config.getSystemTimeFormat(), is("")); }
@Override public TimestampFormatter apply(@Nonnull StaplerRequest request) { TimestamperConfig config = GlobalConfiguration.all().get(TimestamperConfig.class); return new TimestampFormatterImpl( config.getSystemTimeFormat(), config.getElapsedTimeFormat(), request); }