Skip to content

Commit

Permalink
LOGBACK-833 - unit test improvements to check that a local timestamp …
Browse files Browse the repository at this point in the history
…property really was set
  • Loading branch information
diroussel committed Apr 19, 2013
1 parent e8a2394 commit af2b445
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions logback-classic/src/test/input/joran/timestamp-local.xml
@@ -1,4 +1,7 @@
<configuration>
<timestamp key="testTimestamp" datePattern="yyyy-MM"/>
<property scope="system"
name="ch.qos.logback.classic.joran.JoranConfiguratorTest.timestampLocal"
value="today is ${testTimestamp}"/>
</configuration>

Expand Up @@ -15,6 +15,8 @@

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import ch.qos.logback.classic.jul.JULHelper;
Expand Down Expand Up @@ -326,13 +328,27 @@ public void timestamp() throws JoranException, IOException,
@Test
public void timestampLocal() throws JoranException, IOException,
InterruptedException {

String sysProp = "ch.qos.logback.classic.joran.JoranConfiguratorTest.timestampLocal";
System.setProperty(sysProp, "");

String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
+ "timestamp-local.xml";
configure(configFileAsStr);

// It's hard to test the local variable has been set, as it's not
// visible from here. But instead we test that it's not set in the
// context. And check that a system property has been replaced with the
// contents of the local variable

String r = loggerContext.getProperty("testTimestamp");
assertNull(r);

String exprected = "today is " + new SimpleDateFormat("yyyy-MM").format(new Date());
String sysPropValue = System.getProperty(sysProp);
assertEquals(exprected, sysPropValue);


}

@Test
Expand Down

0 comments on commit af2b445

Please sign in to comment.