首页 > 解决方案 > 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 的类层次结构中找不到与名称测试匹配的方法。

我已经尝试了几乎所有可能的方法来让它工作..

声明

标签: javajunitmockitopowermockpowermockito

解决方案


推荐阅读