-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathReflective_T.java
More file actions
92 lines (73 loc) · 2.06 KB
/
Reflective_T.java
File metadata and controls
92 lines (73 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package unquietcode.tools.esm;
import org.junit.Test;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
/**
* @author Ben Fagin
* @version 2013-07-15
*/
public class Reflective_T {
@Test
public void testSimpleReflective() {
final AtomicInteger enteringBlue = new AtomicInteger();
final AtomicInteger exitingBlue = new AtomicInteger();
final AtomicInteger enteringGreen = new AtomicInteger();
final AtomicInteger enteringAny = new AtomicInteger();
final AtomicInteger exitingAny = new AtomicInteger();
final AtomicInteger transitionAny = new AtomicInteger();
ReflectiveStateMachine sm = new ReflectiveStateMachine() {
@Override
protected void declareTransitions() {
addTransition(null, "blue");
addTransition("blue", "green");
addTransition("green", null);
}
public void onEnteringBlue(String state) {
assertEquals("blue", state);
enteringBlue.incrementAndGet();
}
public void onBlue() {
enteringBlue.incrementAndGet();
}
public void onExitingBlue() {
exitingBlue.incrementAndGet();
}
public void onGreen() {
enteringGreen.incrementAndGet();
}
public void onEntering() {
enteringAny.incrementAndGet();
}
public void onExiting() {
exitingAny.incrementAndGet();
}
public void onTransition() {
transitionAny.incrementAndGet();
}
};
sm.transition("blue");
sm.transition("green");
sm.transition(null);
assertEquals(2, enteringBlue.get());
assertEquals(1, exitingBlue.get());
assertEquals(1, enteringGreen.get());
assertEquals(3, enteringAny.get());
assertEquals(3, exitingAny.get());
assertEquals(3, transitionAny.get());
}
@Test(expected=CustomException.class)
public void testException() {
ReflectiveStateMachine sm = new ReflectiveStateMachine() {
public void onBlue() {
throw new CustomException("error");
}
};
sm.addTransition(null, "blue");
sm.transition("blue");
}
private static class CustomException extends RuntimeException {
public CustomException(String msg) {
super(msg);
}
}
}