在以下文件中,我想使用Mockito测试try方法的代码块。我想使用j单元模拟测试mongo.java文件。 SoaXMLLoggerRequestDTO是模型类文件,mongo.java是具有方法logRequestResponseXMLsWithTimeStamps的类文件。
mongo.java
public void logRequestResponseXMLsWithTimeStamps(final String requestType, final String requestXML,
final String responseXML, final long startTime, final long endTime, final long timeTaken,
final String status, final String userId, final String estimatetId) {
try {
SoaXMLLoggerRequestDTO loggerDTO = new SoaXMLLoggerRequestDTO();
loggerDTO.setRequestType(requestType);
loggerDTO.setRequestXml(requestXML);
loggerDTO.setResponseXml(responseXML);
loggerDTO.setCreatedBy(userId);
loggerDTO.setEstimateId(estimatetId + "");
loggerDTO.setStatus(status);
loggerDTO.setLatency(timeTaken);
LogExecutorService.writeToLog(new ESLoggerTask(loggerDTO, ESLoggerTask.IndexName.BNPSOALOG));
} catch (Exception e) {
LOGGER.error("Error in logRequestResponseXMLsWithTimeStamps : ", e);
throw new DAOException("Error logRequestResponseXMLs", e);
}
}
SoaXMLLoggerRequestDTO
public class SoaXMLLoggerRequestDTO extends LoggerRequestDTO{
private String requestType;
private String requestXml;
private String responseXml;
private Long latency;
private String status;
private String estimateId;
public String getRequestType() {
return requestType;
}
public void setRequestType(String requestType) {
this.requestType = requestType;
}
public String getRequestXml() {
return requestXml;
}
public void setRequestXml(String requestXml) {
this.requestXml = requestXml;
}
public String getResponseXml() {
return responseXml;
}
public void setResponseXml(String responseXml) {
this.responseXml = responseXml;
}
public Long getLatency() {
return latency;
}
public void setLatency(Long latency) {
this.latency = latency;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getEstimateId() {
return estimateId;
}
public void setEstimateId(String estimateId) {
this.estimateId = estimateId;
}
}
答案 0 :(得分:0)
以下代码将测试try块代码。
public void test_logRequestResponseXMLsWithTimeStamps() {
estimateServicesMongoDao.logRequestResponseXMLsWithTimeStamps("ert", "rtr", "werffer",2L,0, 0, "drgfdf","sefw", null);
}