Message-ID: <1103137518.11633.1406581520992.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_11632_1571646367.1406581520992" ------=_Part_11632_1571646367.1406581520992 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Suppose you wish to test a class which is dependent on a static = call. Is there a way to mock out that call?=20
Yes, there are two suggested approaches:=20
Here we are calling
Arrays.sort() directly - normally that =
would be the problematic code within your class under test.
More details about this approach: ExpandoMetaClass - Adding static methods=20
If you are in a position to use Java 6, you should also consider using J= Mockit.=20 =20
Where MockArrays is the following Java class:=20 =20
We use a Java class here because otherwise JMockit tries to replace othe=
GroovyObject methods (e.g. getMetaClass, invokeMethod, ...) =
and won't find them inside the
java.util.Arrays class. Obvious=
ly, if your redefining a Groovy class, you can use another Groovy class.
More details: Usin= g JMockit with Groovy.