### Question:
FlowRuleChecker { static Node selectReferenceNode(FlowRule rule, Context context, DefaultNode node) { String refResource = rule.getRefResource(); int strategy = rule.getStrategy(); if (StringUtil.isEmpty(refResource)) { return null; } if (strategy == RuleConstant.STRATEGY_RELATE) { return ClusterBuilderSlot.getClusterNode(refResource); } if (strategy == RuleConstant.STRATEGY_CHAIN) { if (!refResource.equals(context.getName())) { return null; } return 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 testSelectNodeForEmptyReference() { DefaultNode node = mock(DefaultNode.class); Context context = mock(Context.class); FlowRule rule = new FlowRule("testSelectNodeForEmptyReference") .setCount(1) .setStrategy(RuleConstant.STRATEGY_CHAIN); assertNull(FlowRuleChecker.selectReferenceNode(rule, context, node)); }
@Test public void testSelectNodeForRelateReference() { String refResource = "testSelectNodeForRelateReference_refResource"; DefaultNode node = mock(DefaultNode.class); ClusterNode refCn = mock(ClusterNode.class); ClusterBuilderSlot.getClusterNodeMap().put(new StringResourceWrapper(refResource, EntryType.IN), refCn); Context context = mock(Context.class); FlowRule rule = new FlowRule("testSelectNodeForRelateReference") .setCount(1) .setStrategy(RuleConstant.STRATEGY_RELATE) .setRefResource(refResource); assertEquals(refCn, FlowRuleChecker.selectReferenceNode(rule, context, node)); }
@Test public void testSelectReferenceNodeForContextEntrance() { String contextName = "good_context"; DefaultNode node = mock(DefaultNode.class); Context context = mock(Context.class); FlowRule rule = new FlowRule("testSelectReferenceNodeForContextEntrance") .setCount(1) .setStrategy(RuleConstant.STRATEGY_CHAIN) .setRefResource(contextName); when(context.getName()).thenReturn(contextName); assertEquals(node, FlowRuleChecker.selectReferenceNode(rule, context, node)); when(context.getName()).thenReturn("other_context"); assertNull(FlowRuleChecker.selectReferenceNode(rule, context, node)); }