Let's say I have the following class like this:
public class MyClass {
public static final Logger LOG = Logger.getLogger(MyClass.class);
public void myMethod(String condition) {
if (condition.equals("terrible")) {
LOG.error("This is terrible!");
return;
}
//rest of logic in method
}
}
My unit test for MyClass
looks something like this:
@Test
public void testTerribleCase() throws ModuleException {
myMethod("terrible");
//Log should contain "This is terrible!" or assert that error was logged
}
Is there some way to determine that the log contains the specific String "This is terrible"? Or even better, is there a way to determine if it logged an error at all without looking for a specific String value?
Create a custom filter to look for the message and record if it was ever seen.