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