From: Steve F. <st...@m3...> - 2004-05-03 18:15:05
|
Short answer. Because Java is not really an object-oriented language, you can't mock static methods. You have to have an instance to talk to. Looks like you'll have to wrap the static code in something that can be instantiated. If you really don't want to do that, you might have to try something like using Aspects to intercept, although that has its own issues. S Laurent Duperval wrote: >> I have a class that I want to mock which is completely static (all >> public methods are static). How do I do this? Create a mock that >> extends and overrides every method or is there a better way? >> > > Let me expand this a little: I'm writing a servlet. The parameters of > the servlet have to be sent to a bunch of static methods that do some > sort of magic on them. When testing, I want to replace the real static > call to mocked calls that will throw exceptions and stuff like that. I'm > not testing the static methods. I want to see how the class that calls > the static methods reacts. |