In the invoke(..)
method you use, the type of the parameters for the method are resolved from the type of elements in your Object[]
. Since yours contains an Integer
, jmockit will try to find a method that accepts and Integer
. It will fail since such a method doesn't exist.
No compatible method found: extractMessageObjects(java.lang.Integer)
Instead, you can use the overloaded method that accepts the parameter types
Deencapsulation.invoke(new Example(), "extractMessageObjects",
new Class<?>[] { Object[].class }, (Object) new Object[] { 1 });
So that it can find the appropriate method correctly without hints from the type of arguments you use. Note that you have to cast the last argument so that it is used as the only element in the target Object[]
parameter of the Deencapsulation.invoke(..)
method.