Class TestLogHandler
java.lang.Object
java.util.logging.Handler
com.google.common.testing.TestLogHandler
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
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
-
Constructor Details
-
TestLogHandler
public TestLogHandler()
-
-
Method Details
-
publish
-
flush
-
close
-
clear
public void clear() -
getStoredLogRecords
-