Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top