@Test
public void shouldHaveBestRuleAlwaysSetJoinAlgorithmToNestedLoopIfConditionIsDescendantNode() {

    PlanNode join = new PlanNode(Type.JOIN, selector("Ancestor"), selector("Descendant"));
    PlanNode ancestorSource = new PlanNode(Type.SOURCE, join, selector("Ancestor"));
    PlanNode descendantSource = new PlanNode(Type.SOURCE, join, selector("Descendant"));
    // Set the join type and condition ...
    JoinCondition joinCondition = new DescendantNodeJoinCondition(selector("Ancestor"), selector("Descendant"));
    join.setProperty(Property.JOIN_CONDITION, joinCondition);
    join.setProperty(Property.JOIN_TYPE, JoinType.INNER);
    // Execute the rule ...
    PlanNode result = bestRule.execute(context, join, new LinkedList<OptimizerRule>());
    assertThat(result, is(sameInstance(join)));
    assertThat(join.getProperty(Property.JOIN_TYPE, JoinType.class), is(JoinType.INNER));
    assertThat(join.getProperty(Property.JOIN_ALGORITHM, JoinAlgorithm.class), is(JoinAlgorithm.NESTED_LOOP));
    assertThat(join.getProperty(Property.JOIN_CONDITION, JoinCondition.class), is(sameInstance(joinCondition)));
    assertChildren(join, ancestorSource, descendantSource);
}