public class TestLogHandler
extends java.util.logging.Handler
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());
}
| Modifier and Type | Field and Description |
|---|---|
private java.util.List<java.util.logging.LogRecord> |
list
We will keep a private list of all logged records
|
| Constructor and Description |
|---|
TestLogHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
void |
close() |
void |
flush() |
java.util.List<java.util.logging.LogRecord> |
getStoredLogRecords()
Returns a snapshot of the logged records.
|
void |
publish(java.util.logging.LogRecord record)
Adds the most recently logged record to our list.
|
private final java.util.List<java.util.logging.LogRecord> list
public void publish(java.util.logging.LogRecord record)
publish in class java.util.logging.Handlerpublic void flush()
flush in class java.util.logging.Handlerpublic void close()
close in class java.util.logging.Handlerpublic void clear()
public java.util.List<java.util.logging.LogRecord> getStoredLogRecords()