【发布时间】:2014-09-14 09:44:37
【问题描述】:
我有一个类的以下方法。
public Response getProb(long Id) throws ResourceException
{
final Response response = new Response();
JSONObject headerObject = new JSONObject();
String message = null;
int status = 0;
try
{
JSONObject getProb = new JSONObject();
getProb.put("id", Id);
if (commonDao.validateIdCheck(getProb))
{
headerObject.put(CommonConstants.LASTMOD_DATE, commonDao.lastModDate(Id));
response.setResource(headerObject);
message="Retuned Successfully";
}
response.setStatus(message, status);
}
catch (JSONException exception)
{
throw new ResourceException(CommonErrorConstants.JSON_EXCEPTION, exception);
}
catch (ResourceException exception)
{
throw exception;
}
catch (Exception exception)
{
throw new ResourceException(CommonErrorConstants.GENERAL_EXCEPTION, exception);
}
return response;
}
使用 mockito 的 junit 测试用例将提供 100% 的代码覆盖率。
【问题讨论】: