In the setup of the unit test:
- Get the same logger
- Make it non-additive
Add an appender which remembers the messages in a list:
public class TestAppender extends AppenderSkeleton {
public List messages = new ArrayList();
public void doAppend(LoggingEvent event) {
messages.add( event.getMessage().toString() );
}
}
Add the appender to the logger
Now you can call your code. After the test, you will find all log messages in the list. Add the log level if you want (messages.add( event.getLevel() + " " + event.getMessage() );).
In tearDown(), remove the appender again and enable additivity.