我有以下代码:

    sshCPList.add(new SSHParameter("ssh root@io1", "Password:", "(yes/no)?"));
    sshCPList.add(new SSHParameter(rootpwd, rootPrompt, null));
    sshCPList.add(new SSHParameter("ssh root@io1", "Password:", "(yes/no)?"));
    sshCPList.add(new SSHParameter(rootpwd, rootPrompt, null));
    if(!ssh2.sendSshShellCommandToUnknownHost(sshCPList)){
        theLogger.error("Failed to Authorize the PMF function to login as root");
        result = false;
    }


我想定义以下内容:

when(ssh2.sendSshShellCommandToUnknownHost(*a specific List which contains the four SSHParameter object or has 4 items or sonmething*).thenReturn(false);


问题是我无法将List定义为正确的输入。

有什么建议或解决方案吗?

最佳答案

您可以使用eq(T value),其中value是该特定列表。

就像是:

List<SSHParameter> expectedList = prepareExpectedList();
when(ssh2.sendSshShellCommandToUnknownHost(eq(expectedList)).thenReturn(false)


prepareExpectedList();返回要在测试中提供的输入的equals列表。

http://docs.mockito.googlecode.com/hg/latest/org/mockito/Matchers.html

08-05 15:37