title: How to mock native methods using jMockit
body: <p>I'm trying to use jMockit to stub out a call to netscape.javascript.JSObject which is unfortunately an abstract class with a few native methods in it, both of which don't play well with jMockit. Is there any way for me to stub this out, either with jMockit, or using plain java (I'd prefer not having to introduce a new library if possible)? The code I'm trying to inject the mock in looks something like the following (don't ask):</p>
  
  <blockquote>
    <p>JSObject win = JSObject.getWindow(this);<br>
       String someVal = (String) win.call("foo", new String[] {""});</p>
  </blockquote>
  
  <p>Unfortunately I can't modify the code in question (once again, don't ask), so the only way I can do any sort of unit testing on it is if I can figure out how to stub out or otherwise eliminate the calls to JSObject. My current mock implementation returns a new instance of itself for the call to <em>getWindow</em>, and returns a constant string for the call to <em>call</em> but of course it fails at runtime complaining about </p>
  
  <blockquote>
    <p>class redefinition failed: attempted to change method modifiers</p>
  </blockquote>
  
  <p>which from my research I've discovered means it's attempting to mock a native method.</p>
  
  <p>Edit: Due to the target platform I need to use JDK 1.5 to build/test so any solution must be viable on 1.5.</p>