我正在调用此方法返回一个空列表..
public static List<String> getAttribute(@Nullable Subject subject, String key) {
return Collections.emptyList();
}
忽略此方法的简单性。
我有一个测试方法:
@Test
public void testGetRequesterGroupsOnSubject() {
List<String> testData = new ArrayList<>();
testData.add("admin");
mockStatic(SecurityUtils.class);
mock(SubjectUtils.class);
doReturn(principalCollection).when(currentSubject).getPrincipals();
doReturn(testData).when(SubjectUtils.getAttribute(currentSubject, SubjectUtils.ROLE_CLAIM_URI));
assertEquals(sfa.getRequesterGroups(), new ArrayList<>());
}
SubjectUtils是具有上述方法的类。但是,即使getAttribute返回一个空列表,我不应该期望这会重新调整我的字符串列表吗? (TESTDATA)
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod();
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, you naughty developer!
3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed