@Test
public void testPatternWithMultipleStagesAndOneOrMore() {

    Pattern<String, Integer> pattern = new QueryBuilder<String, Integer>()
            .select(STAGE_1).where((event) -> event.value() == 0)
            .then()
            .select(STAGE_2).oneOrMore().where((event) -> event.value() % 2 == 0)
            .then()
            .select(STAGE_3).where((event) -> event.value() > 100)
            .build();
    StagesFactory<String, Integer> factory = new StagesFactory<>();
    Stages<String, Integer> patternStages = factory.make(pattern);
    List<Stage<String, Integer>> stages = patternStages.getAllStages();
    Assert.assertEquals(5, stages.size());
    // stage FINAL
    final Stage<String, Integer> stage0 = stages.get(0);
    Assert.assertEquals(Stage.StateType.FINAL, stage0.getType());
    // stage 3
    final Stage<String, Integer> stage3 = stages.get(1);
    Assert.assertEquals(Stage.StateType.NORMAL, stage3.getType());
    Assert.assertEquals(STAGE_3, stage3.getName());
    Assert.assertEquals(EdgeOperation.BEGIN, stage3.getEdges().get(0).getOperation());
    Assert.assertEquals(stage0.getName(), stage3.getEdges().get(0).getTarget().getName());
    // stage 2
    final Stage<String, Integer> stage2 = stages.get(2);
    Assert.assertEquals(Stage.StateType.NORMAL, stage2.getType());
    Assert.assertEquals(STAGE_2, stage2.getName());
    Assert.assertEquals(EdgeOperation.TAKE, stage2.getEdges().get(0).getOperation());
    Assert.assertEquals(stage3.getName(), stage2.getEdges().get(0).getTarget().getName());
    Assert.assertEquals(EdgeOperation.PROCEED, stage2.getEdges().get(1).getOperation());
    Assert.assertEquals(stage3.getName(), stage2.getEdges().get(1).getTarget().getName());
    // stage 2 (internal)
    final Stage<String, Integer> internalStage2 = stages.get(3);
    Assert.assertEquals(Stage.StateType.NORMAL, internalStage2.getType());
    Assert.assertEquals(STAGE_2, internalStage2.getName());
    Assert.assertEquals(EdgeOperation.BEGIN, internalStage2.getEdges().get(0).getOperation());
    // stage BEGIN
    final Stage<String, Integer> stage1 = stages.get(4);
    Assert.assertEquals(Stage.StateType.BEGIN, stage1.getType());
    Assert.assertEquals(STAGE_1, stage1.getName());
}