### Question:
FlowRuleChecker { static Node selectNodeByRequesterAndStrategy( FlowRule rule, Context context, DefaultNode node) { String limitApp = rule.getLimitApp(); int strategy = rule.getStrategy(); String origin = context.getOrigin(); if (limitApp.equals(origin) && filterOrigin(origin)) { if (strategy == RuleConstant.STRATEGY_DIRECT) { return context.getOriginNode(); } return selectReferenceNode(rule, context, node); } else if (RuleConstant.LIMIT_APP_DEFAULT.equals(limitApp)) { if (strategy == RuleConstant.STRATEGY_DIRECT) { return node.getClusterNode(); } return selectReferenceNode(rule, context, node); } else if (RuleConstant.LIMIT_APP_OTHER.equals(limitApp) && FlowRuleManager.isOtherOrigin(origin, rule.getResource())) { if (strategy == RuleConstant.STRATEGY_DIRECT) { return context.getOriginNode(); } return selectReferenceNode(rule, context, node); } return null; }  void checkFlow(Function<String, Collection<FlowRule>> ruleProvider, ResourceWrapper resource,
                          Context context, DefaultNode node, int count, boolean prioritized); boolean canPassCheck(/*@NonNull*/ FlowRule rule, Context context, DefaultNode node,
                                                    int acquireCount); boolean canPassCheck(/*@NonNull*/ FlowRule rule, Context context, DefaultNode node, int acquireCount,
                                                    boolean prioritized);  }### Answer:
@Test public void testDefaultLimitAppFlowSelectNode() { DefaultNode node = mock(DefaultNode.class); ClusterNode cn = mock(ClusterNode.class); when(node.getClusterNode()).thenReturn(cn); Context context = mock(Context.class); FlowRule rule = new FlowRule("testDefaultLimitAppFlowSelectNode").setCount(1); assertEquals(cn, FlowRuleChecker.selectNodeByRequesterAndStrategy(rule, context, node)); }
@Test public void testCustomOriginFlowSelectNode() { String origin = "appA"; String limitAppB = "appB"; DefaultNode node = mock(DefaultNode.class); DefaultNode originNode = mock(DefaultNode.class); ClusterNode cn = mock(ClusterNode.class); when(node.getClusterNode()).thenReturn(cn); Context context = mock(Context.class); when(context.getOrigin()).thenReturn(origin); when(context.getOriginNode()).thenReturn(originNode); FlowRule rule = new FlowRule("testCustomOriginFlowSelectNode").setCount(1); rule.setLimitApp(origin); assertEquals(originNode, FlowRuleChecker.selectNodeByRequesterAndStrategy(rule, context, node)); rule.setLimitApp(limitAppB); assertNull(FlowRuleChecker.selectNodeByRequesterAndStrategy(rule, context, node)); }
@Test public void testOtherOriginFlowSelectNode() { String originA = "appA"; String originB = "appB"; DefaultNode node = mock(DefaultNode.class); DefaultNode originNode = mock(DefaultNode.class); ClusterNode cn = mock(ClusterNode.class); when(node.getClusterNode()).thenReturn(cn); Context context = mock(Context.class); when(context.getOriginNode()).thenReturn(originNode); FlowRule ruleA = new FlowRule("testOtherOriginFlowSelectNode").setCount(1); ruleA.setLimitApp(originA); FlowRule ruleB = new FlowRule("testOtherOriginFlowSelectNode").setCount(2); ruleB.setLimitApp(RuleConstant.LIMIT_APP_OTHER); FlowRuleManager.loadRules(Arrays.asList(ruleA, ruleB)); when(context.getOrigin()).thenReturn(originB); assertEquals(originNode, FlowRuleChecker.selectNodeByRequesterAndStrategy(ruleB, context, node)); when(context.getOrigin()).thenReturn(originA); assertNull(FlowRuleChecker.selectNodeByRequesterAndStrategy(ruleB, context, node)); }