@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 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 testSetElapsedTimeFormat() { TimestamperConfig config = new TimestamperConfig(); config.setElapsedTimeFormat(customElapsedTimeFormat); assertThat(config.getElapsedTimeFormat(), is(customElapsedTimeFormat)); }
@Test public void testFromXmlCustomElapsedTimeFormat() { TimestamperConfig config = fromXml(xml(null, customElapsedTimeFormat)); assertThat(config.getElapsedTimeFormat(), is(customElapsedTimeFormat)); }
@Test public void testFromXmlCustomSystemTimeFormat() { TimestamperConfig config = fromXml(xml(customSystemTimeFormat, null)); assertThat(config.getSystemTimeFormat(), is(customSystemTimeFormat)); }
@Test public void testToXmlCustomElapsedTimeFormat() { TimestamperConfig config = new TimestamperConfig(); config.setElapsedTimeFormat(customElapsedTimeFormat); assertThat(toXml(config), is(xml(null, customElapsedTimeFormat))); }
@Test public void testToXmlCustomSystemTimeFormat() { TimestamperConfig config = new TimestamperConfig(); config.setSystemTimeFormat(customSystemTimeFormat); assertThat(toXml(config), is(xml(customSystemTimeFormat, null))); }
@Test public void testNoJenkinsInstance() { Whitebox.setInternalState(Jenkins.class, "theInstance", (Jenkins) null); TimestamperConfig config = TimestamperConfig.get(); assertThat(config, is(nullValue())); }
@Test public void testSetElapsedTimeFormatEmpty() { TimestamperConfig config = new TimestamperConfig(); config.setElapsedTimeFormat(""); assertThat(config.getElapsedTimeFormat(), is("")); }
@Override public TimestampFormatter apply(@Nonnull StaplerRequest request) { TimestamperConfig config = GlobalConfiguration.all().get(TimestamperConfig.class); return new TimestampFormatterImpl( config.getSystemTimeFormat(), config.getElapsedTimeFormat(), request); }