### Question:
ConnectorParentsMatchConnectionHandler extends AbstractParentsMatchHandler<ConnectorParentsMatchConnectionHandler, GraphConnectionContext> { @Override public RuleViolations evaluate(final RuleExtension rule, final GraphConnectionContext context) { return evaluateConnection(rule, context); } protected  ConnectorParentsMatchConnectionHandler(); @Inject  ConnectorParentsMatchConnectionHandler(final DefinitionManager definitionManager); @Override Class<ConnectorParentsMatchConnectionHandler> getExtensionType(); @Override Class<GraphConnectionContext> getContextType(); @Override boolean accepts(final RuleExtension rule,
                           final GraphConnectionContext context); @Override RuleViolations evaluate(final RuleExtension rule,
                                   final GraphConnectionContext context);  }### Answer:
@Test @SuppressWarnings("unchecked") public void testFailEvaluateParentDefinition() { when(connectionContext.getSource()).thenReturn(Optional.of(nodeA)); when(connectionContext.getTarget()).thenReturn(Optional.of(nodeC)); when(ruleExtension.getTypeArguments()).thenReturn(new Class[]{ParentDefinition.class}); final RuleViolations violations = tested.evaluate(ruleExtension, connectionContext); assertNotNull(violations); assertViolations(violations, false); }
@Test @SuppressWarnings("unchecked") public void testNoParentDefinition() { when(connectionContext.getSource()).thenReturn(Optional.of(nodeA)); when(connectionContext.getTarget()).thenReturn(Optional.of(nodeC)); when(ruleExtension.getTypeArguments()).thenReturn(new Class[]{}); final RuleViolations violations = tested.evaluate(ruleExtension, connectionContext); assertNotNull(violations); assertViolations(violations, true); }
@Test @SuppressWarnings("unchecked") public void testEvaluateNestedParentWithDifferentTypes() { graphHandler.removeChild(rootNode, parentNode); graphHandler.setChild(grandParentNode, parentNode); graphHandler.removeChild(parentNode, nodeA); graphHandler.setChild(grandParentNode, nodeA); when(connectionContext.getSource()).thenReturn(Optional.of(nodeA)); when(connectionContext.getTarget()).thenReturn(Optional.of(nodeB)); when(ruleExtension.getTypeArguments()).thenReturn(new Class[]{ParentDefinition.class}); RuleViolations violations = tested.evaluate(ruleExtension, connectionContext); assertViolations(violations, false); when(ruleExtension.getTypeArguments()).thenReturn( new Class[]{ParentDefinition.class, GrandParentDefinition.class}); violations = tested.evaluate(ruleExtension, connectionContext); assertViolations(violations, false); graphHandler.removeChild(parentNode, nodeB); graphHandler.setChild(grandParentNode, nodeB); violations = tested.evaluate(ruleExtension, connectionContext); assertViolations(violations, true); when(ruleExtension.getTypeArguments()).thenReturn( new Class[]{ParentDefinition.class, RootDefinition.class}); violations = tested.evaluate(ruleExtension, connectionContext); assertViolations(violations, true); }