[英]NullPointerException in Mockito when mocking method with primitive argument
[英]Method with primitive argument using PrivilegedAccessor
在我的Junit中,我嘗試使用PrivilegedAccessor
執行以下方法,但得到NoSuchMethodException: Invalid Method getInsurance
PrivilegedAccessor.invokeMethod(InsuranceRetriever,
"getInsurance", new Object[] { code}, new Class[] {
Long.class});
以下是經過測試的方法聲明。
private InsObj getInsurance(long code)
*請注意,我正在傳遞Long.class,而實際參數是原始long。 如何傳遞原始參數。
嘗試這個:
PrivilegedAccessor.invokeMethod(InsuranceRetriever,
"getInsurance", new Object[] { code },
new Class[] { Long.TYPE });
說明:
基本類型的類對象可在每種基本類型的每個java.lang對象的TYPE靜態最終常量下找到。 Boolean.TYPE
, Integer.TYPE
, Byte.TYPE
, Short.TYPE
, Long.TYPE
等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.