FilterManager { public synchronized Map<Content, List<User>> filterContent(List<Content> parsedContentList) { Map<Content, List<User>> mappedContent = mapContentWithUsers(parsedContentList); return filterContentWithHistory(filterContentWithCache(mappedContent)); }  @Autowired void setFilters(List<ContentFilter> filters); @Autowired void setContentManager(ContentManager contentManager); void setCacheTimeToLive(int cacheTimeToLive); @PostConstruct void init(); synchronized Map<Content, List<User>> filterContent(List<Content> parsedContentList);  }
@Test public void shouldNotAddContentForUser1AndAddToUser2() throws Exception { List<Content> list = new ArrayList<Content>(); list.add(content1); list.add(content2); when(contentManager.getAllContentOfTypeAndName(eq(CONTENT_NAME), eq(TvShow.class))).thenReturn(list); when(contentManager.getUsersWithContentInHistory(eq(parsedContent), any(List.class))).thenReturn(Collections.singletonList(user1)); Map<Content, List<User>> res = filterManager.filterContent(Collections.singletonList(parsedContent)); Assert.assertEquals(1, res.size()); }
@Test public void shouldAddContentWhenUserNotHasInHistory() throws Exception { Map<Content, List<User>> res = filterManager.filterContent(Collections.singletonList(parsedContent)); Assert.assertFalse(res.isEmpty()); }
@Test public void shouldNotAddContentWhenFilterReturnsFalse() throws Exception { when(contentFilter.filterIfPossible(any(Content.class), eq(parsedContent))).thenReturn(false); Map<Content, List<User>> res = filterManager.filterContent(Collections.singletonList(parsedContent)); Assert.assertTrue(res.isEmpty()); }
@Test public void shouldNotAddContentWhenFilterIsNotPossible() throws Exception { when(contentFilter.filterIfPossible(any(Content.class), eq(parsedContent))).thenReturn(null); Map<Content, List<User>> res = filterManager.filterContent(Collections.singletonList(parsedContent)); Assert.assertTrue(res.isEmpty()); }
@Test public void shouldNotAddContentWhenUserAlreadyHasInHistory() throws Exception { when(contentManager.getUsersWithContentInHistory(any(Content.class), any(List.class))).thenReturn(Collections.singletonList(user1)); Map<Content, List<User>> res = filterManager.filterContent(Collections.singletonList(parsedContent)); Assert.assertTrue(res.isEmpty()); }
@Test public void shouldNotAddContentWhenUsersDoesntHaveContentWithName() throws Exception { when(contentManager.getAllContentOfTypeAndName(eq(CONTENT_NAME), eq(TvShow.class))).thenReturn(Collections.<Content> emptyList()); Map<Content, List<User>> res = filterManager.filterContent(Collections.singletonList(parsedContent)); Assert.assertTrue(res.isEmpty()); }