java - Mockito 无法使用谓词函数
问题描述
我有以下测试:
@Test
public void testListIntersectionByRoleIsEmpty() {
when(sfa.getRequesterGroups()).thenReturn(testRoles);
when(shareableMetacard.getAccessGroups()).thenReturn(mockedRoleSet);
assertTrue(sfa.sharedByGroup().test(shareableMetacard));
}
这是测试以下代码:
@VisibleForTesting
Predicate<Share> sharedByGroup() {
return metacard ->
!metacard
.getAccessGroups()
.stream()
.filter(getRequesterGroups()::contains)
.collect(Collectors.toList())
.isEmpty();
}
但是,我收到以下错误:
org.powermock.reflect.exceptions.MethodNotFoundException:在类 java.lang.Object 的类层次结构中找不到与名称测试匹配的方法。
我已经尝试了几乎所有可能的方法来让它工作..
声明
sfa = spy(new SearchFormsApplication(catalogFramework, templateTransformer, endpointUtil));
@org.mockito.Mock Share shareableMetacard;
解决方案
推荐阅读
- c++11 - 为什么在传递给函数后看不到完整的指针数组值
- ios - 如何在 swift 中设置 AppDelegate 以进行推送通知
- c# - 将 ImageSource 转换为位图
- php - 通过键组合单个数组中的值
- intellij-idea - 包含什么 kotlin 库来获取 AbstractKotlinInspection?
- javascript - Angular Reactive 表单渲染问题破坏了表单
- django - 下拉菜单未出现在模板中由 django 呈现的表单中
- matlab - 在图像中寻找像素变化最大的区域
- angular - ng update 和 npm update 有什么区别?
- java - 如何使用比较器实现 Treemap?