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