Suppose you wish to test a class which is dependent on a static call. Is there a way to mock out that call?
Yes, there are two suggested approaches: Using EMC or Using JMockit
Here we are calling
Arrays.sort() directly - normally that would be the problematic code within your class under test.
Where MockArrays is the following Java class:
We use a Java class here because otherwise JMockit tries to replace other Groovy Methods (e.g. getMetaClass, invokeMethod, ...) and won't find them inside the
java.util.Arrays class. Obviously, if your redefining a Groovy class, you can use another Groovy class.
More details on JMockit.