public List<TerminalNode> addRule(RuleImpl rule, InternalRuleBase kBase, Collection<InternalWorkingMemory> workingMemories) throws InvalidPatternException {

        // the list of terminal nodes
        final List<TerminalNode> termNodes = new ArrayList<>();

        // transform rule and gets the array of subrules
        final GroupElement[] subrules = rule.getTransformedLhs( LogicTransformer.getInstance(), kBase.getGlobals() );

        for (int i = 0; i < subrules.length; i++) {
            // creates a clean build context for each subrule
            final BuildContext context = new BuildContext( kBase, workingMemories );
            context.setRule( rule );
            context.setSubRuleIndex( i );

            // if running in STREAM mode, calculate temporal distance for events
            if (EventProcessingOption.STREAM.equals( kBase.getRuleBaseConfiguration().getEventProcessingMode() )) {
                TemporalDependencyMatrix temporal = this.utils.calculateTemporalDistance( subrules[i] );
                context.setTemporalDistance( temporal );
            }

            if (kBase.getRuleBaseConfiguration().isSequential() ) {
                context.setTupleMemoryEnabled( false );
            } else {
                context.setTupleMemoryEnabled( true );
            }

            // adds subrule
            context.setSubRuleIndex(i);
            addSubRule( context, subrules[i], rule );
            // adds the terminal node to the list of terminal nodes

            termNodes.addAll(context.getTerminals());
        }

        return termNodes;
    }
@Test
    public void testAddRuleWithPatterns() {
        final RuleImpl rule = new RuleImpl( "only patterns" );
        final Pattern c1 = new Pattern( 0,
                                new ClassObjectType( String.class ) );
        final Pattern c2 = new Pattern( 1,
                                new ClassObjectType( String.class ) );
        final Pattern c3 = new Pattern( 2,
                                new ClassObjectType( String.class ) );

        final GroupElement lhsroot = GroupElementFactory.newAndInstance();
        lhsroot.addChild( c1 );
        lhsroot.addChild( c2 );
        lhsroot.addChild( c3 );

        rule.setLhs( lhsroot );

        final Consequence consequence = new Consequence<KnowledgeHelper>() {
            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 ValueResolver valueResolver) throws Exception {
                System.out.println( "Consequence!" );
            }

            public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

            }

            public void writeExternal(ObjectOutput out) throws IOException {

            }
            
            public String getName() {
                return "default";
            }
        };

        rule.setConsequence( consequence );

        final List terminals = this.builder.addRule( rule, this.rulebase, Collections.emptyList() );

        assertThat(terminals.size()).as("Rule must have a single terminal node").isEqualTo(1);

        final RuleTerminalNode terminal = (RuleTerminalNode) terminals.get( 0 );

    }