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