UserForm extends BasePage implements Serializable { public String save() throws IOException { setUserRoles(getRequest().getParameterValues("userForm:userRoles")); for (int i = 0; (userRoles != null) && (i < userRoles.length); i++) { String roleName = userRoles[i]; user.addRole(roleManager.getRole(roleName)); } if (user.getId() != null && user.getId() == 0 || user.getVersion() != null && user.getVersion() == 0) { user.setId(null); user.setVersion(null); } Integer originalVersion = user.getVersion(); try { user = userManager.saveUser(user); } catch (AccessDeniedException ade) { log.warn(ade.getMessage()); getResponse().sendError(HttpServletResponse.SC_FORBIDDEN); return null; } catch (UserExistsException e) { addError("errors.existing.user", new Object[] { user.getUsername(), user.getEmail() }); user.setVersion(originalVersion); return "editProfile"; } if (!"list".equals(getParameter("from"))) { addMessage("user.saved"); return "home"; } else { if ("".equals(getParameter("userForm:version"))) { addMessage("user.added", user.getFullName()); try { sendUserMessage(user, getText("newuser.email.message", user.getFullName()), RequestUtil.getAppURL(getRequest())); } catch (MailException me) { addError(me.getCause().getLocalizedMessage()); } return "list"; } else { addMessage("user.updated.byAdmin", user.getFullName()); return "editProfile"; } } }  void setId(String id); User getUser(); void setUser(User user); void setRoleManager(RoleManager roleManager); String add(); String cancel(); String edit(); boolean isRememberMe(); String save(); String delete(); String getFrom(); @SuppressWarnings("unchecked") Map<String, String> getAvailableRoles(); String[] getUserRoles(); void setUserRoles(String[] userRoles); String getCountry(); void setCountry(String country);  }
@Test public void testSave() throws Exception { User user = userManager.getUser("-1"); user.setPassword("user"); user.setConfirmPassword("user"); bean.setUser(user); assertEquals("home", bean.save()); assertNotNull(bean.getUser()); assertFalse(bean.hasErrors()); }