import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
/**
* info test
*
* @author East271536394
* @version 2012-4-17 下午6:39:51
*/
public class InfoContactCmdTest extends AbstractContactClientTestBase {
@Mock
private RegistrationClientInfo clientInfo = null;
@Mock
private EPPClient client = null;
@Mock
private EPPResult eppResult = null;
@Mock
EPPContactInfoResp eppContactInfoResp = null;
@Mock
RegistrationContact contact = null;
private String password="password";
@Before
public void init() throws Exception {
contact = this.createNewContact();
}
@Test
public void infoContactTest() throws Exception {
//构造一个Info联系人命令的返回结果,并使其返回码为1000,即操作成功
when(eppResult.getCode()).thenReturn(EPPResult.SUCCESS);
when(eppContactInfoResp.getResult()).thenReturn(eppResult);
when(eppClientFactory.getClientInstance(clientInfo.getClientId(), clientInfo.getPassword())).thenReturn(client);
doNothing().when(client).login(null);
doNothing().when(client).logout();
when(client.infoEPPContact(contact.getContactId(), password)).thenReturn(eppContactInfoResp);
//断言
assertTrue(registrationContactClientService.infoContactCmd(contact.getContactId(), clientInfo,password).getResult()
.getCode() == EPPResult.SUCCESS);
verify(eppResult).getCode();
verify(eppContactInfoResp).getResult();
verify(client).infoEPPContact(contact.getContactId(), password);
}
}
java mock 测试
最新推荐文章于 2024-05-25 13:29:26 发布