Further attempt to fix CI log test failures

pull/7/head
Phillip Webb 12 years ago
parent 83d3b508a8
commit 02ae46d40e

@ -22,8 +22,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.logging.LogManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Jdk14Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -38,15 +37,20 @@ import static org.junit.Assert.assertTrue;
public class JavaLoggerConfigurerTests {
private PrintStream savedOutput;
private ByteArrayOutputStream output;
private Jdk14Logger logger;
@Before
public void init() throws SecurityException, IOException {
this.savedOutput = System.out;
this.output = new ByteArrayOutputStream();
System.setOut(new PrintStream(this.output));
LogManager.getLogManager().readConfiguration(
getClass().getResourceAsStream("logging.properties"));
getClass().getResourceAsStream("/logging.properties"));
this.logger = new Jdk14Logger(getClass().getName());
this.savedOutput = System.err;
this.output = new ByteArrayOutputStream();
System.setErr(new PrintStream(this.output));
}
@After
@ -54,7 +58,7 @@ public class JavaLoggerConfigurerTests {
System.clearProperty("LOG_FILE");
System.clearProperty("LOG_PATH");
System.clearProperty("PID");
System.setOut(this.savedOutput);
System.setErr(this.savedOutput);
}
private String getOutput() {
@ -64,11 +68,10 @@ public class JavaLoggerConfigurerTests {
@Test
public void testDefaultConfigLocation() throws Exception {
JavaLoggerConfigurer.initLogging("classpath:logging-nondefault.properties");
Log logger = LogFactory.getLog(JavaLoggerConfigurerTests.class);
logger.info("Hello world");
this.logger.info("Hello world");
String output = getOutput().trim();
assertTrue("Wrong output:\n" + output, output.contains("Hello world"));
assertTrue("Wrong output:\n" + output, output.startsWith("["));
assertTrue("Wrong output:\n" + output, output.contains("INFO"));
}
@Test(expected = FileNotFoundException.class)

@ -23,6 +23,7 @@ import java.util.logging.LogManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.SLF4JLogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -42,6 +43,8 @@ public class LoggingApplicationContextInitializerTests {
private LoggingApplicationContextInitializer initializer = new LoggingApplicationContextInitializer();
private Log logger = new SLF4JLogFactory().getInstance(getClass());
private PrintStream savedOutput;
private ByteArrayOutputStream output;
@ -71,8 +74,7 @@ public class LoggingApplicationContextInitializerTests {
public void testDefaultConfigLocation() {
GenericApplicationContext context = new GenericApplicationContext();
this.initializer.initialize(context);
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
logger.info("Hello world");
this.logger.info("Hello world");
String output = getOutput().trim();
assertTrue("Wrong output:\n" + output, output.contains("Hello world"));
assertFalse("Wrong output:\n" + output, output.contains("???"));
@ -93,8 +95,7 @@ public class LoggingApplicationContextInitializerTests {
}
});
this.initializer.initialize(context);
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
logger.info("Hello world");
this.logger.info("Hello world");
String output = getOutput().trim();
assertTrue("Wrong output:\n" + output, output.contains("Hello world"));
assertFalse("Wrong output:\n" + output, output.contains("???"));

@ -5,4 +5,5 @@ java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.formatter = org.springframework.bootstrap.logging.StandardFormatter
java.util.logging.SimpleFormatter.format = %4$s: %5$s [%1$tc]%n

Loading…
Cancel
Save