我的测试中有以下代码......
val list : List[MyClass] = List(new MyClass)
...
doNothing().when(localLib).handleDelete(anyString(), anyString(), anyInt(), eq(list))
这会引发以下编译异常
Error:(890, 83) type mismatch;
found : Boolean
required: java.util.List[my.package.MyClass]
doNothing().when(localLib).handleDelete(anyString(), anyString(), anyInt(), eq(list))
^
答案 0 :(得分:2)
您必须使用scalatest
吗?与Mockito
存在冲突,其中一个*Spec
特征定义了自己的eq
,您最终会引用该Mockito
匹配而不是impot org.mockito.Matcher.{ eq => mockEq }
匹配器。
尝试添加显式导入:mockEq
然后在需要匹配器时使用eq
代替function getStatData($y,$m,$d=false){
if(isset($y) && is_numeric($y) && isset($m) && is_numeric($m)){
// use str_pad
$m=str_pad($m, 2, '0', STR_PAD_LEFT);
if($d){
// use str_pad
$d=str_pad($d, 2, '0', STR_PAD_LEFT);
$y= 'days/'.$y;
$data = file_get_contents(STATDIR.'/'.$y.'/'.$m.'_'.$d.'.json');
}
else {
$data = file_get_contents(STATDIR.'/'.$y.'_'.$m.'.json');
}
return json_decode($data, true);
}
else return false;
}
print_r(getStatData('2016','07','08'));
。
答案 1 :(得分:0)
eq(list)
确实是布尔值,检查签名。你应该嘲笑最后一个论点:
doNothing().when(localLib)
.handleDelete(anyString(), anyString(), anyInt(), any[List[MyClass]])