Skip to content

Instantly share code, notes, and snippets.

@kikers25
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikers25/8a6435e207f855f235c7 to your computer and use it in GitHub Desktop.
Save kikers25/8a6435e207f855f235c7 to your computer and use it in GitHub Desktop.
TestUserServiceStubs
public class TestUserService {
private static final Email EMAIL = new Email("user@company.com");
private final class StubUserDAO implements UserDAO {
public User findUserBy(Email email) {
return userWithPassword("other_password");
}
}
private UserDAO stubUserDAO;
private UserService userService;
@Before
public void initialization() {
stubUserDAO = new StubUserDAO();
userService = new UserService(stubUserDAO);
}
@Test
public void //
should_throw_exception_when_passwords_are_different_version1() throws Exception {
try {
userService.signIn(EMAIL, new Password("password"));
fail("No threw exception");
} catch (AuthenticationException e) {
// ok
}
}
@Test(expected = AuthenticationException.class)
public void //
should_throw_exception_when_passwords_are_different_version2() throws Exception {
userService.signIn(EMAIL, new Password("password"));
}
private User userWithPassword(String password) {
User user = new User();
user.setPassword(password);
return user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment