大家好我試圖嘲弄它以列表類型作爲參數的代碼細節有些部分私有方法如下:如何模擬一個私有方法,它使用功率模擬將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