### Question:
MrrtReportTemplateFormController { @RequestMapping(method = RequestMethod.GET, params = "templateId") public ModelAndView displayMrrtReportTemplate(HttpServletRequest request, @RequestParam("templateId") MrrtReportTemplate mrrtReportTemplate) { final ModelAndView modelAndView = new ModelAndView(MRRT_REPORT_TEMPLATE_FORM_VIEW); try { modelAndView.addObject("templateBody", mrrtReportTemplateService.getMrrtReportTemplateHtmlBody(mrrtReportTemplate)); modelAndView.addObject("template", mrrtReportTemplate); } catch (IOException exception) { request.getSession() .setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Error occured while dispaying template => " + exception.getMessage()); return new ModelAndView("/module/radiology/radiologyDashboardForm"); } return modelAndView; }  @RequestMapping(method = RequestMethod.GET, params = "templateId") ModelAndView displayMrrtReportTemplate(HttpServletRequest request,
            @RequestParam("templateId") MrrtReportTemplate mrrtReportTemplate);  }### Answer:
@Test public void displayMrrtReportTemplate_shouldReturnTheModelAndViewOfTheReportTemplateFormPageContainingTemplateBodyInModelObject() throws Exception { String templateBody = "<div><p>Test template body</p></div>"; when(mrrtReportTemplateService.getMrrtReportTemplateHtmlBody(mrrtReportTemplate)).thenReturn(templateBody); ModelAndView modelAndView = controller.displayMrrtReportTemplate(request, mrrtReportTemplate); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is(MrrtReportTemplateFormController.MRRT_REPORT_TEMPLATE_FORM_VIEW)); assertThat(modelAndView.getModel() .containsKey("templateBody"), is(true)); String templateBodyFromModel = (String) modelAndView.getModel() .get("templateBody"); assertNotNull(templateBodyFromModel); assertThat(templateBodyFromModel, is(templateBody)); }
@Test public void displayMrrtReportTemplate_shouldReturnTheModelAndViewOfTheRadiologyDashboardPageWithErrorMessageIfIoExceptionIsThrown() throws Exception { when(mrrtReportTemplateService.getMrrtReportTemplateHtmlBody(mrrtReportTemplate)) .thenThrow(new IOException("Error reading file.")); ModelAndView modelAndView = controller.displayMrrtReportTemplate(request, mrrtReportTemplate); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is(RADIOLOGY_DASHBOARD_FORM_VIEW)); String errorMessage = (String) request.getSession() .getAttribute(WebConstants.OPENMRS_ERROR_ATTR); assertNotNull(errorMessage); assertThat(errorMessage, is("Error occured while dispaying template => Error reading file.")); }