### Question:
StaffController { @RequestMapping(method = RequestMethod.POST) public String registerStaff(@ModelAttribute("staff") WebStaff staff, Errors errors, ModelMap model) { log.debug("Register Staff"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "motechmodule.firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "motechmodule.lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "type", "motechmodule.staffType.required"); validateTextLength(errors, "firstName", staff.getFirstName(), MotechConstants.MAX_STRING_LENGTH_OPENMRS); validateTextLength(errors, "lastName", staff.getLastName(), MotechConstants.MAX_STRING_LENGTH_OPENMRS); validateTextLength(errors, "phone", staff.getPhone(), MotechConstants.MAX_STRING_LENGTH_OPENMRS); if (staff.getPhone() != null && !staff.getPhone().matches( MotechConstants.PHONE_REGEX_PATTERN)) { errors.rejectValue("phone", "motechmodule.phoneNumber.invalid"); } if (!errors.hasErrors()) { User user = registrarBean.registerStaff(staff.getFirstName(), staff .getLastName(), staff.getPhone(), staff.getType(), staff.getStaffId()); model.addAttribute("successMsg", (staff.isNew() ? NEW : EDIT).message(user)); } model.addAttribute("staffTypes", registrarBean.getStaffTypes()); return "/module/motechmodule/staff"; }  @InitBinder void initBinder(WebDataBinder binder); @ModelAttribute("staff") WebStaff getWebStaff(); @RequestMapping(method = RequestMethod.GET) String viewStaffForm(@RequestParam(value = "staffId", required = false) String staffId, ModelMap model); @RequestMapping(method = RequestMethod.POST) String registerStaff(@ModelAttribute("staff") WebStaff staff,
                                Errors errors, ModelMap model); void setRegistrarBean(RegistrarBean registrarBean); void setOpenmrsBean(OpenmrsBean openmrsBean);  }### Answer:
@Test public void registerStaff() { RegistrarBean registrarBean = createMock(RegistrarBean.class); Errors errors = createMock(Errors.class); StaffController controller = new StaffController(); controller.setRegistrarBean(registrarBean); ModelMap map = new ModelMap(); WebStaff staff = new WebStaff(); staff.setFirstName("Joseph"); staff.setLastName("Jones"); staff.setPhone("0123456789"); staff.setType("CHO"); expect(errors.getFieldValue("firstName")).andReturn(staff.getFirstName()); expect(errors.getFieldValue("lastName")).andReturn(staff.getLastName()); expect(errors.getFieldValue("type")).andReturn(staff.getType()); expect(errors.hasErrors()).andReturn(false); expect(registrarBean.registerStaff(staff.getFirstName(),staff.getLastName(),staff.getPhone(), staff.getType(),staff.getStaffId())).andReturn(user(staff)); List<String> staffTypes = new ArrayList<String>(); staffTypes.add("CHO"); expect(registrarBean.getStaffTypes()).andReturn(staffTypes); replay(errors,registrarBean); String view = controller.registerStaff(staff, errors, map); verify(errors,registrarBean); assertEquals("/module/motechmodule/staff",view); assertEquals(staffTypes,map.get("staffTypes")); assertEquals("Added user: Name = Joseph Jones, Staff ID = 465",map.get("successMsg")); }