I have a static void method from a different class that is invoked along my code as some sort of logger. In order to automatically test the different use cases of my code I was thinking of checking the logs of the system created by such method.
What I thought is to mock that class and overwrite the behaviour of the method so that it outputs to System.err
. Also, redirecting System.err
as explained here so that I can easily verify the correct functioning of the code.
I do not know how to override the standard behaviour of the method so that it does something (printing to the stderr) instead of what it normally does (by not mocking it) or nothing (what I get my using when(...).thenReturn(...)
)