LikesFeed extends FlattenableFeed<List<Like>> { @Override public List<Like> flatten() { if(users == null) { return new ArrayList<>(); } for(Like like: likes) { like.setUser(users.get(like.getUserId())); like.setPost(posts.get(like.getPostId())); } return likes; }  @Override List<Like> flatten();  }
@Test public void nullFeedReturnsEmptyList() { List<Like> likes = new LikesFeed().flatten(); assertThat(likes, notNullValue()); }
@Test public void returnsLikes() { List<Like> likes = new ArrayList<>(); Map<String, User> users = new HashMap<>(); LikesFeed feed = new LikesFeed(); feed.likes = likes; feed.users = users; feed.posts = new HashMap<>(); assertThat(feed.flatten(), equalTo(likes)); }
@Test public void populatesUsersToLikes() { String id = "someId"; Like like = mock(Like.class); List<Like> likes = Arrays.asList(like); Map<String, User> userMap = new HashMap<>(); User user = mock(User.class); userMap.put(id, user); when(like.getUserId()).thenReturn(id); LikesFeed feed = new LikesFeed(); feed.likes = likes; feed.users = userMap; feed.posts = new HashMap<>(); feed.flatten(); verify(like).setUser(user); }
@Test public void populatesPostsToLikes() { String id = "someId"; Like like = mock(Like.class); List<Like> likes = Arrays.asList(like); Map<String, Post> postMap = new HashMap<>(); Post post = mock(Post.class); postMap.put(id, post); when(like.getPostId()).thenReturn(id); LikesFeed feed = new LikesFeed(); feed.likes = likes; feed.users = new HashMap<>(); feed.posts = postMap; feed.flatten(); verify(like).setPost(post); }