AuthAction { public String enter() { Account account = auth.getAccount(); account.setGravaterHash(Gravater.md5Hex(account.getEmail())); if (service.registerAccount(account)) { auth.setLoggedIn(true); return "chatroom.xhtml?faces-redirect=true"; } else { message.addMessage("error","sameaccount.exists"); return null; } }  String enter(); String exit();  }
@Test public void testEnterOnSuccess() { Auth auth = new Auth(); Account acc = new Account(); acc.setName("test"); acc.setEmail("test@test"); auth.setAccount(acc); PrivateUtil.setField(target, "auth", auth); String act = target.enter(); assertThat(act, is("chatroom.xhtml?faces-redirect=true")); assertThat(auth.isLoggedIn(), is(true)); }
@Test public void testEnterOnError() { Auth auth = new Auth(); Account acc = new Account(); acc.setName("error"); acc.setEmail("test@test"); auth.setAccount(acc); PrivateUtil.setField(target, "auth", auth); String act = target.enter(); assertThat(act, nullValue()); assertThat(auth.isLoggedIn(), is(false)); }