Message-ID: <620487004.797260.1386816536524.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_797259_1467256215.1386816536524" ------=_Part_797259_1467256215.1386816536524 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.