@Test
public void testPatternWithMultipleStages() {

    Pattern<String, Integer> pattern = new QueryBuilder<String, Integer>()
            .select(STAGE_1).where(TestMatcher.isEqualTo(0))
            .then()
            .select(STAGE_2).where((event) -> event.value() % 2 == 0)
            .then()
            .select(STAGE_3).where(TestMatcher.isGreaterThan(100))
            .build();
    StagesFactory<String, Integer> factory = new StagesFactory<>();
    Stages<String, Integer> patternStages = factory.make(pattern);
    List<Stage<String, Integer>> stages = patternStages.getAllStages();
    Assert.assertEquals(4, stages.size());
    Assert.assertEquals(Stage.StateType.FINAL, stages.get(0).getType());
    Assert.assertEquals(Stage.StateType.NORMAL, stages.get(1).getType());
    Assert.assertEquals(STAGE_3, stages.get(1).getName());
    Assert.assertEquals(Stage.StateType.NORMAL, stages.get(2).getType());
    Assert.assertEquals(STAGE_2, stages.get(2).getName());
    Assert.assertEquals(Stage.StateType.BEGIN, stages.get(3).getType());
    Assert.assertEquals(STAGE_1, stages.get(3).getName());
}