Thread.currentThread().getContextClassLoader(),
new Class<?>[]{ UserRepository.class},
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return new User(userName, firstName, lastName.toUpperCase() /*just to illustrate that the mock-instance is used*/);
}
});
mockManager.addMock(mockedUserRepository);
this.windowContext.activateWindow("testWindow");
this.registrationPage.getUser().setUserName(userName);
this.registrationPage.getUser().setFirstName(firstName);
this.registrationPage.getUser().setLastName(lastName);
this.registrationPage.getUser().setPassword("123");
Class<? extends Pages> targetPage = this.registrationPage.register();
Assert.assertEquals(Pages.Login.class, targetPage);
Assert.assertFalse(FacesContext.getCurrentInstance().getMessageList().isEmpty());
Assert.assertEquals(webappMessageBundle.msgUserRegistered(userName), FacesContext.getCurrentInstance().getMessageList().iterator().next().getSummary());
User user = this.userRepository.findByUserName(userName);
Assert.assertNotNull(user);
Assert.assertEquals(firstName, user.getFirstName());
Assert.assertEquals(lastName.toUpperCase(), user.getLastName());
}