Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Yes, there are two suggested approaches:

  • Using EMC

...

  • Using JMockit

Using EMC

Here we are calling Arrays.sort() directly - normally that would be the problematic code within your class under test.

...

Code Block
// Java
public class MockArrays {
  public static void sort(Object[] a) {
    a[1] = "elk";
    a[2] = "ape";
  }
}

We use a Java class here because otherwise JMockit tries to replace other GroovyObject methods (e.g. getMetaClass, invokeMethod, ...) and won't find them inside the java.util.Arrays class. Obviously, if your redefining a Groovy class, you can use another Groovy class.

...