com.google.common.testing
Class TestLogHandler
java.lang.Object
java.util.logging.Handler
com.google.common.testing.TestLogHandler
@Beta
public class TestLogHandler
- extends Handler
Tests may use this to intercept messages that are logged by the code under
test. Example:
TestLogHandler handler;
protected void setUp() throws Exception {
super.setUp();
handler = new TestLogHandler();
SomeClass.logger.addHandler(handler);
addTearDown(new TearDown() {
public void tearDown() throws Exception {
SomeClass.logger.removeHandler(handler);
}
});
}
public void test() {
SomeClass.foo();
LogRecord firstRecord = handler.getStoredLogRecords().get(0);
assertEquals("some message", firstRecord.getMessage());
}
- Since:
- 10.0
- Author:
- Kevin Bourrillion
Methods inherited from class java.util.logging.Handler |
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TestLogHandler
public TestLogHandler()
publish
public void publish(LogRecord record)
- Adds the most recently logged record to our list.
- Specified by:
publish
in class Handler
flush
public void flush()
- Specified by:
flush
in class Handler
close
public void close()
- Specified by:
close
in class Handler
clear
public void clear()
getStoredLogRecords
public List<LogRecord> getStoredLogRecords()
- Fetch the list of logged records
- Returns:
- unmodifiable LogRecord list of all logged records
Copyright © 2010-2012. All Rights Reserved.