-
-
Save kikers25/8a6435e207f855f235c7 to your computer and use it in GitHub Desktop.
TestUserServiceStubs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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