大家好我试图嘲弄它以列表类型作为参数的代码细节有些部分私有方法如下:如何模拟一个私有方法,它使用功率模拟将List类型作为参数?
CustomerVerification类
public class CustomerVerification{
creditCheck.setSuffix(null);
String pinAndPreciseId = null;
try {
pinAndPreciseId = executeCreditCheck(creditCheck, errorResponses, transactionId);
if (pinAndPreciseId.contains("Error")) {
ErrorResponse errorResponse = new ErrorResponse("EXPERIAN", pinAndPreciseId, "E01", transactionId);
errorResponses.add(errorResponse);
customerVerification.setErrorResponses(errorResponses);
return customerVerification;
}
} catch (Exception e) {
throw new EnterpriseCustomerVerificationException(e.getMessage());
}
}
executeCriditCheck类
private String executeCreditCheck(CreditCheck creditCheck, List<ErrorResponse> errorResponses, String transactionId)
throws UnsupportedOperationException, IOException {
LOG.info("Calling experian");
String pinAndPreciseId = null;
String request = null;
String referenceId = null;
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
Date today = new Date();
referenceId = formatter.format(today);
HttpPost experianHttpPost = getExperianHttpPostMethod();
NetConnectRequest netConnectRequest = ExperianCreditMapper.map(creditCheck, eai, dbHost, referenceId,
experianProduct, opInitials, preamble, subCode, arfVersion, venderNumber, vendorVersion, null,
CustomRRDashKeyword);
System.err.println("REQUEST -- " + netConnectRequest.toString());
request = "NETCONNECT_TRANSACTION=" + URLEncoder.encode(netConnectRequest.toString());
experianHttpPost.setEntity(new ByteArrayEntity(request.getBytes("UTF-8")));
HttpResponse response = experianHttpClient.execute(experianHttpPost);
pinAndPreciseId = ExperianCreditMapper.getPIN(response);
return pinAndPreciseId;
}
有人能给我一个关于如何模拟的想法私人方法executeCreditCheck它取3个参数,其中一个是List类型。
注:我在这里只给出了部分代码。请给我一个关于如何模拟executeCreditCheck方法的想法。
A)你会看看在这里使用间谍。 B)基本上你在这里有难以测试的代码。而不是以某种方式测试,而是退一步,想出改进设计的方法......以便测试变得更加容易。 – GhostCat