### Question:
PullMessageFilterChain { boolean needKeep(final PullRequest request, final Buffer message) { for (PullMessageFilter filter : filters) { if (filter.isActive(request, message) && !filter.match(request, message)) { return false; } } return true; } PullMessageFilterChain(final DynamicConfig config);   }### Answer:
@Test public void testPullOnFiltersInactive() throws Exception { Whitebox.setInternalState(pullMessageFilterChain, "filters", Lists.newArrayList(inactiveFilter)); PullRequest request = TestToolBox.createDefaultPullRequest(); Buffer buffer = TestToolBox.createDefaultBuffer(); boolean needKeep = pullMessageFilterChain.needKeep(request, buffer); assertTrue(needKeep); }
@Test public void testPullOnFilterActiveNotMatch() throws Exception { Whitebox.setInternalState(pullMessageFilterChain, "filters", Lists.newArrayList(activeNotMatchFilter)); PullRequest request = TestToolBox.createDefaultPullRequest(); Buffer buffer = TestToolBox.createDefaultBuffer(); boolean needKeep = pullMessageFilterChain.needKeep(request, buffer); assertFalse(needKeep); }
@Test public void testPullOnFilterActiveAndMatch() throws Exception { Whitebox.setInternalState(pullMessageFilterChain, "filters", Lists.newArrayList(activeAndMatchFilter)); PullRequest request = TestToolBox.createDefaultPullRequest(); Buffer buffer = TestToolBox.createDefaultBuffer(); boolean needKeep = pullMessageFilterChain.needKeep(request, buffer); assertTrue(needKeep); }
@Test public void testPullOnMultiFilterButNotMatchOne() throws Exception { Whitebox.setInternalState(pullMessageFilterChain, "filters", Lists.newArrayList(activeAndMatchFilter, activeNotMatchFilter)); PullRequest request = TestToolBox.createDefaultPullRequest(); Buffer buffer = TestToolBox.createDefaultBuffer(); boolean needKeep = pullMessageFilterChain.needKeep(request, buffer); assertFalse(needKeep); }
@Test public void testPullOnMultiFilterAndMatchAll() throws Exception { Whitebox.setInternalState(pullMessageFilterChain, "filters", Lists.newArrayList(activeAndMatchFilter, activeAndMatchFilter)); PullRequest request = TestToolBox.createDefaultPullRequest(); Buffer buffer = TestToolBox.createDefaultBuffer(); boolean needKeep = pullMessageFilterChain.needKeep(request, buffer); assertTrue(needKeep); }
@Test public void testPullOnMultiFilterAndInactiveAll() throws Exception { Whitebox.setInternalState(pullMessageFilterChain, "filters", Lists.newArrayList(inactiveFilter, inactiveFilter)); PullRequest request = TestToolBox.createDefaultPullRequest(); Buffer buffer = TestToolBox.createDefaultBuffer(); boolean needKeep = pullMessageFilterChain.needKeep(request, buffer); assertTrue(needKeep); }