...
| Code Block |
|---|
// non-mocked first to prove it works normally String[] things = [ 'dog', 'ant', 'bee', 'cat' ] Arrays.sort(things) println things // => {"ant", "bee", "cat", "dog"} Arrays.metaClass.'static'.sort = { a -> a[0] = 'ewe' a[1] = 'fox' } things = [ 'dog', 'ant', 'bee', 'cat' ] Arrays.sort(things) println things // => {"ewe", "fox", "bee", "cat"} |
...
| Code Block |
|---|
// require(url:'https://jmockit.dev.java.net', jar='jmockit.jar') // require(url:'https://jmockit.dev.java.net', jar='jmockit-asm2.jar') // needs to be run with "-javaagent:jmockit.jar" // and "-Xbootclasspath/a:jmockit.jar;.;jmockit-asm2.jar" // The bootclasspath option is only required because we are mocking // a class from the java.* package (part of the bootclasspath for Java) import mockit.Mockit // non-mocked first to show normal case String[] things = [ 'dog', 'ant', 'bee', 'cat' ] Arrays.sort(things) println things // => {"ant", "bee", "cat", "dog"} Mockit.redefineMethods(Arrays, MockArrays) things = [ 'dog', 'ant', 'bee', 'cat' ] Arrays.sort(things) println things // => {"dog", "elk", "ape", "cat"} |
...