PasswordHint extends BasePage { public String execute() { getFacesContext().getViewRoot().setViewId("/passwordHint.xhtml"); if (username == null || "".equals(username)) { log.warn("Username not specified, notifying user that it's a required field."); addError("errors.required", getText("user.username")); return null; } else if (username.endsWith(".xhtml")) { username = username.substring(0, username.indexOf(".xhtml")); } if (log.isDebugEnabled()) { log.debug("Processing Password Hint..."); } try { User user = userManager.getUserByUsername(username); StringBuilder msg = new StringBuilder(); msg.append("Your password hint is: ").append(user.getPasswordHint()); msg.append("\n\nLogin at: ").append(RequestUtil.getAppURL(getRequest())); message.setTo(user.getEmail()); String subject = '[' + getText("webapp.name") + "] " + getText("user.passwordHint"); message.setSubject(subject); message.setText(msg.toString()); mailEngine.send(message); addMessage("login.passwordHint.sent", new Object[] { username, user.getEmail() }); } catch (UsernameNotFoundException e) { log.warn(e.getMessage()); addError("login.passwordHint.error", username); } catch (MailException me) { addError(me.getCause().getLocalizedMessage()); } return "success"; }  void setUsername(String username); String execute();  }
@Test public void testExecute() throws Exception { Wiser wiser = startWiser(getSmtpPort()); bean.setUsername("user"); assertEquals("success", bean.execute()); assertFalse(bean.hasErrors()); wiser.stop(); assertTrue(wiser.getMessages().size() == 1); assertNotNull(bean.getSession().getAttribute("messages")); }