Hi Sven,
The best thing to do would probably be to introduce an
anti-corruption layer between your code and the native method. E.g.
refactor the method call to its own class and inject an instance of
it as a member variable in MyClass. Then it's mockable by vanilla
EasyMock. If this is not an option for you then you can use a
technique called
partial
mocking or just
suppress
the method. In your case you could do something like this:
import static
org.powermock.api.support.membermodification.MemberModifier.suppress;
import static
org.powermock.api.support.membermodification.MemberMatcher.method;
@RunWith(PowerMockRunner.class)
@PrepareForTest(MyClass.class)
public class MyClassTest {
@Test
public void test() {
suppress(method(MyClass.class, "executeJSNINativeMethod"));
// Run your test
new MyClass().init();
..
}
}
/Johan