1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml2;
18
19 import java.util.Set;
20
21 import org.apache.commons.scxml2.model.EnterableState;
22 import org.apache.commons.scxml2.model.Final;
23 import org.apache.commons.scxml2.model.State;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 public class StatusTest {
29
30 private StateConfiguration stateConfiguration;
31 private Status status;
32
33 @Before
34 public void setUp() {
35 stateConfiguration = new StateConfiguration();
36 status = new Status(stateConfiguration);
37 }
38
39 @Test
40 public void testIsFinalStateFalse() {
41 State state = new State();
42
43 stateConfiguration.enterState(state);
44
45 Assert.assertFalse(status.isFinal());
46 }
47
48 @Test
49 public void testIsFinalStateHasParent() {
50 Final state = new Final();
51 state.setParent(new State());
52
53 stateConfiguration.enterState(state);
54
55 Assert.assertFalse(status.isFinal());
56 }
57
58 @Test
59 public void testIsFinalState() {
60 Final state = new Final();
61
62 stateConfiguration.enterState(state);
63
64 Assert.assertTrue(status.isFinal());
65 }
66
67 @Test
68 public void testGetAllStatesEmptyStatus() {
69
70 Set<EnterableState> returnValue = status.getActiveStates();
71
72 Assert.assertEquals(0, returnValue.size());
73 }
74
75 @Test
76 public void testGetAllStatesContainsParent() {
77 State parent = new State();
78 parent.setId("0");
79 stateConfiguration.enterState(parent);
80 State state = new State();
81 state.setId("1");
82 state.setParent(parent);
83 stateConfiguration.enterState(state);
84
85 Set<EnterableState> returnValue = status.getActiveStates();
86
87 Assert.assertEquals(2, returnValue.size());
88 }
89
90 @Test
91 public void testIsInState() {
92 State parent = new State();
93 parent.setId("0");
94 stateConfiguration.enterState(parent);
95 State state = new State();
96 state.setId("1");
97 state.setParent(parent);
98 stateConfiguration.enterState(state);
99 Assert.assertTrue(status.isInState("0"));
100 Assert.assertTrue(status.isInState("1"));
101 Assert.assertFalse(status.isInState("2"));
102 }
103 }