Last active
December 24, 2017 06:52
-
-
Save adrianvdh/fe692e0c848a69b36e1a68691f5bda4a to your computer and use it in GitHub Desktop.
Tdd examples from http://scholarcoder.com/1392/ttd-intro
This file contains hidden or 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
class UserService { | |
List<User> users = new ArrayList<>(); | |
{ | |
User user = new User(); | |
user.username = "adrianvdh"; | |
user.password = "hello123"; | |
users.add(user); | |
} | |
public User authenticate(String username, String password) { | |
User foundUser = null; | |
for (User userInCollection : users) { | |
if (userInCollection.username.equals(username)) { | |
foundUser = userInCollection; | |
break; | |
} | |
} | |
if(foundUser == null) | |
throw new RuntimeException(String.format("User with username %s could not be found!", username)); | |
return foundUser; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment