Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package truckz.web;
- import org.junit.Assert;
- import org.junit.Test;
- /**
- *
- * @author Eddy
- */
- public class LoginBeanTest {
- class Verification { public boolean verified; }
- @Test
- public void authenticateReturnsCorrectOutcome() {
- final String username = "joebloggs";
- final String password = "secret";
- LoginBeanOut stubLoginBeanOut = new LoginBeanOut() {
- @Override
- public LoginResult login(String username, String password) {
- return LoginResult.SUCCESS;
- }
- };
- FacesContextWrapper stubFacesContextWrapper = new FacesContextWrapper() {
- @Override
- public void addMessage(String componentId, String message) { }
- };
- LoginBean loginBean = new LoginBean(stubLoginBeanOut, stubFacesContextWrapper);
- loginBean.setUsername(username);
- loginBean.setPassword(password);
- String outcome = loginBean.login();
- Assert.assertNotNull(outcome);
- }
- @Test
- public void authenticateSetsMessageForComponent() {
- final String username = "joebloggs";
- final String password = "secret";
- final Verification verification = new Verification();
- LoginBeanOut stubLoginBeanOut = new LoginBeanOut() {
- @Override
- public LoginResult login(String username, String password) {
- return LoginResult.UNKNOWN_USERNAME;
- }
- };
- FacesContextWrapper stubFacesContextWrapper = new FacesContextWrapper() {
- @Override
- public void addMessage(String componentId, String message) {
- verification.verified = (componentId != null) && (message != null);
- }
- };
- LoginBean loginBean = new LoginBean(stubLoginBeanOut, stubFacesContextWrapper);
- loginBean.setUsername(username);
- loginBean.setPassword(password);
- String unused = loginBean.login();
- Assert.assertTrue(verification.verified);
- }
- }
Add Comment
Please, Sign In to add comment