MCPcopy Create free account
hub / github.com/Beh01der/EasyFlow / RunSingleTest

Class RunSingleTest

src/test/java/au/com/ds/ef/RunSingleTest.java:21–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19import static junit.framework.TestCase.assertTrue;
20
21public class RunSingleTest {
22 public enum States implements StateEnum {
23 START, STATE_1, STATE_2, STATE_3, STATE_4
24 }
25
26 public enum Events implements EventEnum {
27 event_1, event_2, event_3, event_4, event_5
28 }
29
30 @Test
31 public void testInvalidEvent() throws LogicViolationError {
32 final Exception[] exception = new Exception[]{null};
33
34 // state machine definition
35 final EasyFlow<StatefulContext> flow =
36
37 from(START).transit(
38 on(event_1).to(STATE_1).transit(
39 on(event_2).finish(STATE_2)
40 )
41 );
42
43 // handlers definition
44 flow
45 .whenError(new ExecutionErrorHandler() {
46 @Override
47 public void call(ExecutionError error, StatefulContext context) {
48 exception[0] = error;
49 }
50 })
51
52 .whenEnter(START, new ContextHandler<StatefulContext>() {
53 @Override
54 public void call(StatefulContext context) throws Exception {
55 context.trigger(event_2);
56 }
57 });
58
59 StatefulContext ctx = new StatefulContext();
60 flow.trace().start(ctx);
61 ctx.awaitTermination();
62
63 assertNotNull("Exception must be thrown during flow execution", exception[0]);
64 assertTrue("Exception type should be ExecutionError", exception[0] instanceof ExecutionError);
65 assertTrue("Exception cause should be LogicViolationError", exception[0].getCause() instanceof LogicViolationError);
66 }
67
68 @Test
69 public void testEventsOrder() throws LogicViolationError {
70 EasyFlow<StatefulContext> flow =
71
72 from(START).transit(
73 on(event_1).to(STATE_1).transit(
74 on(event_2).finish(STATE_2),
75 on(event_3).to(STATE_3).transit(
76 on(event_4).to(STATE_1),
77 on(event_5).finish(STATE_4)
78 )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected