@ruhanga thanks alot.Actually that’s the very method that i refactored , The snippets above are from OrderController1_10Test
so the actual refactoring looks like this
@Override
protected PageableResult doSearch(RequestContext context) throws ObjectNotFoundException {
String patientUuid = context.getRequest().getParameter("patient");
String stat = context.getRequest().getParameter("status");
if (StringUtils.equals(stat, "active") && StringUtils.isBlank(patientUuid)) {
//throw new org.databene.commons.ObjectNotFoundException("Sorry You did not Specify a Patient UUID");
throw new ObjectNotFoundException();
//return new EmptySearchResult();
}
if (patientUuid != null) {
Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass(
Patient.class)).getByUniqueId(patientUuid);
if (patient == null) {
//return new EmptySearchResult();
throw new ObjectNotFoundException();
}
// if the user indicated a specific type, try to delegate to the appropriate subclass handler
if (context.getType() != null) {
PageableResult ret = (PageableResult) findAndInvokeSubclassHandlerMethod(context.getType(),
"getActiveOrders", patient, context);
if (ret != null) {
return ret;
}
}
String careSettingUuid = context.getRequest().getParameter("careSetting");
String asOfDateString = context.getRequest().getParameter("asOfDate");
CareSetting careSetting = null;
Date asOfDate = null;
if (StringUtils.isNotBlank(asOfDateString)) {
asOfDate = (Date) ConversionUtil.convert(asOfDateString, Date.class);
}
if (StringUtils.isNotBlank(careSettingUuid)) {
careSetting = ((CareSettingResource1_10) Context.getService(RestService.class).getResourceBySupportedClass(
CareSetting.class)).getByUniqueId(careSettingUuid);
}
String status = context.getRequest().getParameter("status");
List<Order> orders = OrderUtil.getOrders(patient, careSetting, null, status, asOfDate, context.getIncludeAll());
// if the user indicated a specific type, and we couldn't delegate to a subclass handler above, filter here
if (context.getType() != null) {
filterByType(orders, context.getType());
}
return new NeedsPaging<Order>(orders, context);
}
throw new ObjectNotFoundException();
//return new EmptySearchResult();
//throw new NoResultException("Sorry You Did not Specify a Patient UUID");
}
And either of the two should pass if only order status is passed as param.
We don’t expect a null or "empty result "
The actual methods look like
//@Test
public void doSearch_ReturnExceptionIfNoPatientUuidIsSpecified() throws Exception {
MockHttpServletRequest request = request(RequestMethod.GET, getURI());
SimpleObject results;
String status = "active";
request.setParameter("status", status);
//request.setParameter("patient", PATIENT_UUID);
results = deserialize(handle(request));
Object obj = results.getClass();
assertEquals(obj, new ObjectNotFoundException());
}
@Test
public void doSearch_ReturnExceptionIfNoPatientUuidIsSpecifiedAtAll() throws Exception {
SimpleObject obj = deserialize(handle(newGetRequest(getURI(), new Parameter("status", "active"), new Parameter(
"careSetting", RestTestConstants1_10.CARE_SETTING_UUID), new Parameter("includeAll", "true"))));
assertEquals(new ObjectNotFoundException(), Util.getResultsList(obj));
}