断言错误:验证失败

时间:2015-04-09 08:05:52

标签: powermock easymock

我试图测试这个工作流程

public List<UserOrganization> getUserOrganizations(String username) {
    try {
        LOGGER.debug("Getting organizations for user {}", username);
        ILdapUser ldapUser = ldapUserRest.getUserByUsername(username);
        if (ldapUser == null || StringUtils.isEmpty(ldapUser.getCccUniqueId())) {
            LOGGER.debug("Could not get ldap user for user name {}", username);
            return new ArrayList<>();
        }
       ....

所以我创建了这个测试

@Test
public void testGetUserOrganizationLdapUserNullFlow() throws Exception {
    expect(ldapUserRest.getUserByUsername(USER_NAME)).andReturn(null);
    expectNew(ArrayList.class).andReturn(new ArrayList<UserOrganization>());
    replayAll();
    userOrganizationService.getUserOrganizations(USER_NAME);
    verifyAll();
}

对于我的测试类,我添加了注释@PrepareForTest

@PrepareForTest(ArrayList.class)
public class UserOrganizationServiceTest {

但是当我尝试运行它时,我发现了一个错误

enter image description here

但是,当我使用replay(ldapUserRest)代替replayAll时,测试工作正常。 (当我使用replayAll而不是replay使用模拟参数时,我的大多数测试都失败了。

0 个答案:

没有答案