Within my Junit, I am trying to execute a Method using PrivilegedAccessor as following but getting NoSuchMethodException: Invalid Method getInsurance -

PrivilegedAccessor.invokeMethod(InsuranceRetriever,
                    "getInsurance", new Object[] { code}, new Class[] {
                            Long.class});

Following is the tested method declaration.

private InsObj getInsurance(long code)

*Please note here that i am passing Long.class whereas the real argument is primitive long. How to pass primitive argument.

有帮助吗?

解决方案

Try this:

PrivilegedAccessor.invokeMethod(InsuranceRetriever,
                "getInsurance", new Object[] { code }, 
                new Class[] { Long.TYPE });

Explanation:

The class objects for the primitive types are found under the TYPE static final constant in each of the java.lang objects for each of the primitive types. Boolean.TYPE, Integer.TYPE, Byte.TYPE, Short.TYPE, Long.TYPE etc.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top