RawNewsFeed extends FlattenableFeed<NewsFeed> { @Override public NewsFeed flatten() { EventListFeed eventFeed = new EventListFeed(); eventFeed.events = events; eventFeed.users = users; eventFeed.posts = postMap; List<Event> events = new EventFeedToList().call(eventFeed); PostListFeed postFeed = new PostListFeed(); postFeed.posts = posts; postFeed.users = users; List<Post> posts = new PostFeedToList().call(postFeed); return new NewsFeed(events, posts); }  @Override NewsFeed flatten();  }
@Test public void nullFeedParsesToNotNull() { NewsFeed feed = new RawNewsFeed().flatten(); assertThat(feed, notNullValue()); }
@Test public void populatesUsersToEvents(){ String id = "someId"; RawNewsFeed rawFeed = new RawNewsFeed(); Event event = mock(Event.class); List<Event> events = Arrays.asList(event); when(event.getUserId()).thenReturn(id); Map<String, User> users = new HashMap<>(); User user = mock(User.class); users.put(id, user); rawFeed.events = events; rawFeed.users = users; rawFeed.postMap = new HashMap<>(); rawFeed.flatten(); verify(event).setUser(user); }
@Test public void returnsEvents() { String id = "someId"; RawNewsFeed rawFeed = new RawNewsFeed(); Event event = mock(Event.class); List<Event> events = Arrays.asList(event); when(event.getUserId()).thenReturn(id); Map<String, User> users = new HashMap<>(); User user = mock(User.class); users.put(id, user); rawFeed.events = events; rawFeed.users = users; rawFeed.postMap = new HashMap<>(); NewsFeed feed = rawFeed.flatten(); assertThat(feed.getEvents(), equalTo(events)); }
@Test public void populatesUsersToPosts() { String id = "someId"; RawNewsFeed rawFeed = new RawNewsFeed(); Post post = mock(Post.class); when(post.getUserId()).thenReturn(id); List<Post> posts = Arrays.asList(post); Map<String, User> users = new HashMap<>(); User user = mock(User.class); users.put(id, user); rawFeed.posts = posts; rawFeed.users = users; rawFeed.postMap = new HashMap<>(); rawFeed.flatten(); verify(post).setUser(user); }
@Test public void returnsPosts() { String id = "someId"; RawNewsFeed rawFeed = new RawNewsFeed(); Post post = mock(Post.class); when(post.getUserId()).thenReturn(id); List<Post> posts = Arrays.asList(post); Map<String, User> users = new HashMap<>(); User user = mock(User.class); users.put(id, user); rawFeed.posts = posts; rawFeed.users = users; rawFeed.postMap = new HashMap<>(); NewsFeed feed = rawFeed.flatten(); assertThat(feed.getPosts(), equalTo(posts)); }