@Test
	public void testEventsOrder() throws LogicViolationError {
		EasyFlow<StatefulContext> flow =

		    from(START).transit(
				on(event_1).to(STATE_1).transit(
                    on(event_2).finish(STATE_2),
                    on(event_3).to(STATE_3).transit(
                        on(event_4).to(STATE_1),
                        on(event_5).finish(STATE_4)
                    )
                )
		    );

		final List<Integer> actualOrder = new ArrayList<Integer>();

        flow
		    .whenEnter(START, new ContextHandler<StatefulContext>() {
                @Override
                public void call(StatefulContext context) throws Exception {
                    actualOrder.add(1);
                    context.trigger(event_1);
                }
            })
            .whenLeave(START, new ContextHandler<StatefulContext>() {
                @Override
                public void call(StatefulContext context) {
                    actualOrder.add(2);
                }
            })

            .whenEnter(STATE_1, new ContextHandler<StatefulContext>() {
                @Override
                public void call(StatefulContext context) throws Exception {
                    actualOrder.add(3);
                    context.trigger(event_2);
                }
            }).whenLeave(STATE_1, new ContextHandler<StatefulContext>() {
                @Override
                public void call(StatefulContext context) {
                    actualOrder.add(4);
                }
            })

            .whenEnter(STATE_2, new ContextHandler<StatefulContext>() {
                @Override
                public void call(StatefulContext context) {
                    actualOrder.add(5);
                }
            }).whenLeave(STATE_2, new ContextHandler<StatefulContext>() {
                @Override
                public void call(StatefulContext context) {
                    throw new RuntimeException("It never leaves the final state");
                }
            })

            .whenFinalState(new StateHandler<StatefulContext>() {
                @Override
                public void call(StateEnum state, StatefulContext context) {
                    actualOrder.add(6);
                }
            });

        StatefulContext ctx = new StatefulContext();
        flow.trace().start(ctx);
        ctx.awaitTermination();

		int i = 0;
		for (Integer order : actualOrder) {
			i++;
			if (order != i) {
				throw new RuntimeException("Events called not in order expected: " + i + " actual: " + order);
			}
		}
	}