[英]How to capture varargs
我有靜態方法,我想捕獲可變參數
Executor ex = new Executor();
ex.execute(String nodeName, boolean status, Property ... properties);
ArgumentCaptor<Property> propertyCaptor = ArgumentCaptor.forClass(Property.class);
verify(ex).execute(anyString(), anyBoolean(), propertyCaptor.capture);
propertyCaptor .getValue() - 不起作用????
我不確定您到底要測試什么,但以下方法有效:
class SpecialExecutor implements Executor {
@Override
public void execute(Runnable command) {
}
public void execute(String nodeName, boolean status, Property... properties) {
}
};
@Test
public void test() {
SpecialExecutor ex = new SpecialExecutor();
ArgumentCaptor<Property> propertyCaptor = ArgumentCaptor.forClass(Property.class);
verify(ex).execute(anyString(), anyBoolean(), any(Property[].class));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.