### Question:
ProfileController { @RequestMapping(method = RequestMethod.POST) public String updateProfile(ModelMap model, @RequestParam(required = false) String referringPageId, @ModelAttribute("updatedUser") UserForm updatedUser) { User user = userService.getAuthenticatedUser(); logger.info("Updating " + user.getUsername() + " profile information"); user.setGivenName(updatedUser.getGivenName()); user.setFamilyName(updatedUser.getFamilyName()); user.setDisplayName(updatedUser.getDisplayName()); user.setAboutMe(updatedUser.getAboutMe()); user.setStatus(updatedUser.getStatus()); user.setEmail(updatedUser.getEmail()); userService.updateUserProfile(user); addAttributesToModel(model, user, referringPageId); return ViewNames.REDIRECT + "app/person/" + user.getUsername(); } @Autowired  ProfileController(UserService userService, PageService pageService); @RequestMapping(value = {"/{username:.*}"}, method = RequestMethod.GET) String viewProfileByUsername(@PathVariable String username, ModelMap model, @RequestParam(required = false) String referringPageId, HttpServletResponse response); @RequestMapping(value = {"/id/{userid:.*}"}, method = RequestMethod.GET) String viewProfile(@PathVariable String userid, ModelMap model, @RequestParam(required = false) String referringPageId, HttpServletResponse response); @RequestMapping(method = RequestMethod.POST) String updateProfile(ModelMap model,
                                @RequestParam(required = false) String referringPageId,
                                @ModelAttribute("updatedUser") UserForm updatedUser); static void addNavItemsToModel(String view, ModelMap model, String referringPageId, User user, List<Person> friendRequests);  }### Answer:
@Test public void updateProfile_ShouldUpdateAuthenticatedUser() { final ModelMap model = new ModelMap(); final int modelSize = 2; final String referringPageId = "1"; final String USERNAME = "canonical"; String userProfile = new String(ModelKeys.USER_PROFILE); final User authUser = new UserImpl(); authUser.setUsername(USERNAME); authUser.setStatus("Single"); authUser.setGivenName("Test"); authUser.setFamilyName("Rave"); authUser.setAboutMe("Test User"); authUser.setEmail("testuser@rave.com"); final UserForm updatedUser = new UserForm(); updatedUser.setStatus("Married"); updatedUser.setGivenName("Test"); updatedUser.setFamilyName("Rave"); updatedUser.setAboutMe("Test User"); updatedUser.setEmail("testuser@rave.com"); expect(userService.getAuthenticatedUser()).andReturn(authUser).anyTimes(); userService.updateUserProfile(authUser); replay(userService); String view = profileController.updateProfile(model, referringPageId, updatedUser); assertThat(model, CoreMatchers.notNullValue()); assertThat(model.size(), CoreMatchers.equalTo(modelSize)); assertThat(model.containsAttribute(userProfile), CoreMatchers.equalTo(true)); assertThat(model.get(userProfile), CoreMatchers.notNullValue()); assertEquals(updatedUser.getStatus(), authUser.getStatus()); assertThat(view, is("redirect:/app/person/" + USERNAME)); verify(userService); }