Search code examples
javamockingjmockit

How static calls are mocked with java agent like in jmockit?


I came to know that Jmockit does not use custom class loader to mock the static call but instead uses the java agent .

I am aware of doing it throughcustom class loader. Can anyone explain how java agent help here at high level ?

I believe java agent must be intercepting the call and call stub instead of original implementation .
But how java agent helps here in interception as its usually done by proxy ?


Solution

  • As far as I remember with a Java Agent you can manipulate the class objects as they are loaded. So JMockit can just insert anything into the class it wants. or needs.

    Here you find a tutorial that gives an introduction about Java Agents and how to create some: http://www.javabeat.net/introduction-to-java-agents/