### Question:
BehaviorExecutionFilter extends OncePerRequestFilter { private boolean execute(final HttpServletRequest request, final HttpServletResponse response, final List<Behavior> behaviors) throws IOException { boolean gotCommittingBehavior = false; for (Behavior behavior : behaviors) { if (logger.isInfoEnabled()) { logger.info((dryRun ? "[dry-run]" : "") + "Executing behavior: " + (behavior != null ? behavior.name() : "null")); } if (!dryRun) { behavior.act(request, response); gotCommittingBehavior |= behavior.isCommitting(); } } return !gotCommittingBehavior; } BehaviorExecutionFilter(final BehaviorProvider behaviorProvider); void setDryRun(final boolean dryRun);  }### Answer:
@Test void should_build_facts() throws ServletException, IOException { MockHttpServletRequest request = loginRequest(); request.setAttribute("nixer.flag", true); request.setAttribute("other.flag", true); execute(request); verify(behaviorProvider).get(factsArgumentCaptor.capture()); Facts facts = factsArgumentCaptor.getValue(); assertNotNull(facts); assertEquals(facts.getFact("nixer.flag"), true); }
@Test void should_execute_behavior() throws ServletException, IOException { MockHttpServletRequest request = loginRequest(); Behavior behavior = committingBehavior(); givenBehaviors(behavior); execute(request); verifyExecuted(behavior); }
@Test void should_skip_processing_for_not_matching_request() throws ServletException, IOException { MockHttpServletRequest request = logoutRequest(); execute(request); verifyZeroInteractions(behaviorProvider); }
@Test void should_execute_both_behaviors() throws ServletException, IOException { MockHttpServletRequest request = loginRequest(); Behavior committingBehavior = committingBehavior(); Behavior nonCommittingBehavior = nonCommittingBehavior(); Behavior otherNonCommittingBehavior = nonCommittingBehavior(); givenBehaviors(nonCommittingBehavior, committingBehavior, otherNonCommittingBehavior); execute(request); verifyExecuted(committingBehavior); verifyExecuted(nonCommittingBehavior); verifyExecuted(otherNonCommittingBehavior); }
@Test void should_execute_only_first_committing_behavior() throws ServletException, IOException { MockHttpServletRequest request = loginRequest(); Behavior firstCommittingBehavior = committingBehavior(); Behavior secondCommittingBehavior = committingBehavior(); givenBehaviors(firstCommittingBehavior, secondCommittingBehavior); execute(request); verifyExecuted(firstCommittingBehavior); verifyNotExecuted(secondCommittingBehavior); }
@Test void should_stop_executing_filter_chain_on_committing_behavior() throws ServletException, IOException { MockHttpServletRequest request = loginRequest(); Behavior committingBehavior = committingBehavior(); givenBehaviors(committingBehavior); execute(request); verifyExecuted(committingBehavior); verifyFilterChainIgnored(request); }