It is possible to have two classes in Java with the same fully qualified class name, if they are loaded by different class loaders. I don't know how practical it would be to take advantage of that, but at least theoretically it would be possible to mock a static method.
There is also the technique suggested by Michael Feathers in "Working Effectively with Legacy Code" whereby you isolate the offending calls in a handful of protected methods. You then subclass the class under test and stub out these methods.
For .NET programmers, I've written some code that will generate an assembly with the described interface declaration and forwarding implementation. For more information, refer to the testing library http://jolt.codeplex.com.
It is possible to have two classes in Java with the same fully qualified class name, if they are loaded by different class loaders. I don't know how practical it would be to take advantage of that, but at least theoretically it would be possible to mock a static method.
ReplyDeleteThere is also the technique suggested by Michael Feathers in "Working Effectively with Legacy Code" whereby you isolate the offending calls in a handful of protected methods. You then subclass the class under test and stub out these methods.
ReplyDeleteYou could "mock" the static method with JMockit. However, the pattern suggested here seems like a much better solution.
ReplyDeleteFor .NET programmers, I've written some code that will generate an assembly with the described interface declaration and forwarding implementation. For more information, refer to the testing library http://jolt.codeplex.com.
ReplyDelete