How do I mock static methods in a class with easymock?

JavaRocky picture JavaRocky · Jul 2, 2010 · Viewed 69.8k times · Source

Suppose I have a class like so:

public class StaticDude{
    public static Object getGroove() {
        // ... some complex logic which returns an object
    };
}

How do I mock the static method call using easy mock? StaticDude.getGroove().

I am using easy mock 3.0

Answer

Ben J picture Ben J · Jul 2, 2010

Not sure how to with pure EasyMock, but consider using the PowerMock extensions to EasyMock.

It has a lot of cool functions for doing just what you need - https://github.com/jayway/powermock/wiki/MockStatic