CommentsFeed extends FlattenableFeed<List<Comment>> { @Override public List<Comment> flatten() { if(comments == null) { return new ArrayList<>(); } for(Comment comment: comments) { comment.setUser(users.get(comment.getUserId())); } return comments; }  @Override List<Comment> flatten();  }
@Test public void nullFeedReturnsEmptyList() { List<Comment> comments = new CommentsFeed().flatten(); assertThat(comments, notNullValue()); }
@Test public void returnsListOfComments() { CommentsFeed feed = new CommentsFeed(); Comment comment = mock(Comment.class); List<Comment> comments = Arrays.asList(comment); feed.comments = comments; feed.users = new HashMap<>(); assertThat(feed.flatten(), equalTo(comments)); }
@Test public void populatesUsersToComments() { String id = "userId"; CommentsFeed feed = new CommentsFeed(); Comment comment = mock(Comment.class); when(comment.getUserId()).thenReturn(id); List<Comment> comments = Arrays.asList(comment); User user = mock(User.class); Map<String, User> users = new HashMap<>(); users.put(id, user); feed.comments = comments; feed.users = users; feed.flatten(); verify(comment).setUser(user); }