Skip to content

Instantly share code, notes, and snippets.

@babjo
Last active July 27, 2021 13:57
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 babjo/003aa8388e110e3e720f156ad6a76b78 to your computer and use it in GitHub Desktop.
Save babjo/003aa8388e110e3e720f156ad6a76b78 to your computer and use it in GitHub Desktop.
class FakeBlogRepository implements BlogRepository {
private Map<String, List<Post>> data = new HashMap<>();
private long lastPostId = 0L;
public long save(long userId, Post post) {
lastPostId++;
post.setId(lastPostId);
List<Post> posts = data.get(userId);
if (posts == null) {
posts = new ArrayList<>();
}
posts.add(post);
return lastPostId;
}
public findByUserId(long userId) {
List<Post> posts = data.get(userId);
if (posts == null) {
throw new IllegalStateException("Not found");
}
return posts;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment