TrendController { protected String getIndex(IPatientObject item) { String index; if (item instanceof Result) { index = LAB_INDEX; } else if (item instanceof VitalSign) { index = VITAL_INDEX; } else { throw new IllegalArgumentException("Trend type is invalid. Valid types: result, vitalSign"); } return index; }  @Autowired void setLinkService(ILinkService linkService); @Autowired void setGenericPatientObjectDao(IGenericPatientObjectDAO genericPatientObjectDao); @RequestMapping(value = "/vpr/trend/**", method = RequestMethod.GET, params = "format=xml") String renderXml(HttpServletRequest request); @RequestMapping(value = "/vpr/trend/**", method = RequestMethod.GET, params = "format=json") ModelAndView renderJson(HttpServletRequest request); @RequestMapping(value = "/vpr/trend/**", method = RequestMethod.GET, params = "format=extjs") @ResponseBody String renderExtJs(@RequestParam("format") String format, HttpServletRequest request); static final String LAB_INDEX; static final String VITAL_INDEX; }
@Test public void testGetIndex() { assertEquals(TrendController.LAB_INDEX, tc.getIndex(new Result())); assertEquals(TrendController.VITAL_INDEX, tc.getIndex(new VitalSign())); try { assertEquals(TrendController.VITAL_INDEX, tc.getIndex(new Problem())); Assert.assertFalse(true); } catch (Exception e) { assertEquals("Trend type is invalid. Valid types: result, vitalSign", e.getMessage()); } }