1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml2.model;
18
19 import java.util.List;
20
21 import org.apache.commons.scxml2.SCXMLExecutor;
22 import org.apache.commons.scxml2.SCXMLTestHelper;
23 import org.junit.Assert;
24 import org.junit.Test;
25
26 public class StateTest {
27
28 @Test
29 public void testGetTransitionsListNull() {
30 State state = new State();
31 Assert.assertNull(state.getTransitionsList("event"));
32 }
33
34 @Test
35 public void testGetTransitionsList() {
36 State state = new State();
37 state.getTransitionsList().add(new Transition());
38 Assert.assertNotNull(state.getTransitionsList(null));
39 }
40
41 @Test
42 public void testAddTransitionDoesNotContainKey() {
43 Transition transition = new Transition();
44 transition.setEvent("event");
45
46 State state = new State();
47 state.addTransition(transition);
48
49 List<Transition> events = state.getTransitionsList("event");
50
51 Assert.assertEquals(1, events.size());
52 Assert.assertEquals("event", events.get(0).getEvent());
53 }
54
55 @Test
56 public void testAddTransitionContainKey() {
57 Transition transition1 = new Transition();
58 transition1.setEvent("event");
59
60 Transition transition2 = new Transition();
61 transition2.setEvent("event");
62
63 State state = new State();
64 state.addTransition(transition1);
65 state.addTransition(transition2);
66
67 List<Transition> events = state.getTransitionsList("event");
68
69 Assert.assertEquals(2, events.size());
70 }
71
72 @Test
73 public void testGetTransitionList() {
74 Transition transition1 = new Transition();
75 transition1.setEvent("event");
76
77 Transition transition2 = new Transition();
78 transition2.setEvent("event");
79
80 State state = new State();
81 state.addTransition(transition1);
82 state.addTransition(transition2);
83
84 List<Transition> events = state.getTransitionsList();
85
86 Assert.assertEquals(2, events.size());
87 }
88
89 @Test
90 public void testHasHistoryEmpty() {
91 State state = new State();
92 Assert.assertFalse(state.hasHistory());
93 }
94
95 @Test
96 public void testHasHistory() {
97 History history = new History();
98
99 State state = new State();
100 state.addHistory(history);
101
102 Assert.assertTrue(state.hasHistory());
103 }
104
105 @Test
106 public void testIsSimple() {
107 State state = new State();
108 Assert.assertTrue(state.isSimple());
109 }
110
111 @Test
112 public void testIsSimpleHasChildren() {
113 State state1 = new State();
114
115 State state = new State();
116 state.addChild(state1);
117
118 Assert.assertFalse(state.isSimple());
119 }
120
121 @Test
122 public void testIsCompositeFalse() {
123 State state = new State();
124 Assert.assertFalse(state.isComposite());
125 }
126
127 @Test
128 public void testIsCompositeParallel() {
129 State child = new State();
130
131 State state = new State();
132 state.addChild(child);
133
134 Assert.assertTrue(state.isComposite());
135 }
136
137 @Test
138 public void testIsCompositeHasChildren() {
139 State state1 = new State();
140
141 State state = new State();
142 state.addChild(state1);
143
144 Assert.assertTrue(state.isComposite());
145 }
146
147 @Test
148 public void testIsRegion() {
149 State state = new State();
150 state.setParent(new Parallel());
151
152 Assert.assertTrue(state.isRegion());
153 }
154
155 @Test
156 public void testIsRegionNotParallel() {
157 State state = new State();
158 state.setParent(new State());
159
160 Assert.assertFalse(state.isRegion());
161 }
162
163 @Test
164 public void testInitialAttribute() throws Exception {
165 SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/state-01.xml");
166 exec.go();
167 Assert.assertEquals("s11", exec.getStatus().getStates().iterator().next().getId());
168 }
169 }