I have a unit test which checks that a class writes the log statements
it's supposed to.
The following code works, but I was wondering if there isn't a better or
easier way to do this.
Here's what I have now:
public void testCloseChannels() {
Logger rootLogger = (Logger)
LoggerFactory.getLogger(
LoggerContext.ROOT_NAME);
Appender<LoggingEvent> appender =
rootLogger.getAppender("console");
appender.addFilter(new Filter() {
@Override
public FilterReply decide(Object o) {
LoggingEvent event = (LoggingEvent) o;
if (event.getMessage().equals("Failed to close channel.")) {
expectedLogEntryCount.incrementAndGet();
return FilterReply.DENY;
}
return FilterReply.NEUTRAL;
}
});
close(null, new UnclosableChannelStub(), null,
new ChannelStub(), new ChannelStub());
assertEquals("Exactly 1 failure should have been logged.",
1, expectedLogEntryCount.intValue());
appender.clearAllFilters();
}
Regards,
Claus Nielsen
_______________________________________________
Logback-user mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-user