Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Adrianvdh/1736b395d499140042f772d2738516f5 to your computer and use it in GitHub Desktop.
Save Adrianvdh/1736b395d499140042f772d2738516f5 to your computer and use it in GitHub Desktop.
public class UserRepositoryImpl implements UserRepository {
Set<User> users = new HashSet<>();
{
User user = new User();
user.username = "adrianvdh";
user.password = "hello123";
users.add(user);
}
@Override
public User findByUsername(String username) {
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