1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.scxml.model;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import junit.framework.Test;
23  import junit.framework.TestCase;
24  import junit.framework.TestSuite;
25  
26  public class StateTest extends TestCase {
27  
28      public StateTest(String testName) {
29          super(testName);
30      }
31  
32      public static Test suite() {
33          return new TestSuite(StateTest.class);
34      }
35  
36      public static void main(String args[]) {
37          String[] testCaseName = { StateTest.class.getName()};
38          junit.textui.TestRunner.main(testCaseName);
39      }
40      
41      private State state;
42      
43      public void setUp() {
44          state = new State();
45      }
46      
47      public void testGetTransitionsListNull() {
48          assertNull(state.getTransitionsList("event"));
49      }
50      
51      public void testGetTransitionsList() {
52          List values = new ArrayList();
53          
54          state.getTransitions().put("event", values);
55          
56          assertNotNull(state.getTransitionsList("event"));
57      }
58      
59      public void testAddTransitionDoesNotContainKey() {
60          Transition transition = new Transition();
61          transition.setEvent("event");
62          
63          state.addTransition(transition);
64          
65          List events = (List)state.getTransitions().get("event");
66          
67          assertEquals(1, events.size());
68          assertEquals("event", ((Transition)events.get(0)).getEvent());
69      }
70      
71      public void testAddTransitionContainKey() {
72          Transition transition1 = new Transition();
73          transition1.setEvent("event");
74  
75          Transition transition2 = new Transition();
76          transition2.setEvent("event");
77  
78          state.addTransition(transition1);
79          state.addTransition(transition2);
80          
81          List events = (List)state.getTransitions().get("event");
82          
83          assertEquals(2, events.size());
84      }
85      
86      public void testGetTransitionList() {
87          Transition transition1 = new Transition();
88          transition1.setEvent("event");
89  
90          Transition transition2 = new Transition();
91          transition2.setEvent("event");
92  
93          state.addTransition(transition1);
94          state.addTransition(transition2);
95          
96          List events = state.getTransitionsList();
97          
98          assertEquals(2, events.size());
99      }
100     
101     public void testHasHistoryEmpty() {
102         assertFalse(state.hasHistory());
103     }
104 
105     public void testHasHistory() {
106         History history = new History();
107         
108         state.addHistory(history);
109         
110         assertTrue(state.hasHistory());
111     }
112     
113     public void testIsSimple() {
114         assertTrue(state.isSimple());
115     }
116     
117     public void testIsSimpleParallel() {
118         Parallel parallel = new Parallel();
119         
120         state.setParallel(parallel);
121         
122         assertFalse(state.isSimple());
123     }
124     
125     public void testIsSimpleHasChildren() {
126         State state1 = new State();
127         
128         state.addChild(state1);
129         
130         assertFalse(state.isSimple());
131     }
132     
133     public void testIsCompositeFalse() {
134         assertFalse(state.isComposite());
135     }
136     
137     public void testIsCompositeParallel() {
138         Parallel parallel = new Parallel();
139         
140         state.setParallel(parallel);
141         
142         assertTrue(state.isComposite());
143     }
144     
145     public void testIsCompositeHasChildren() {
146         State state1 = new State();
147         
148         state.addChild(state1);
149         
150         assertTrue(state.isComposite());
151     }
152     
153     public void testIsRegion() {
154         state.setParent(new Parallel());
155         
156         assertTrue(state.isRegion());
157     }
158     
159     public void testIsRegionNotParallel() {
160         state.setParent(new State());
161         
162         assertFalse(state.isRegion());
163     }
164     
165     public void testIsOrthogonal() {
166         Parallel parallel = new Parallel();
167         
168         state.setParallel(parallel);
169         
170         assertTrue(state.isOrthogonal());
171     }
172     
173     public void testIsOrthogonalFalse() {
174         assertFalse(state.isOrthogonal());
175     }
176 
177 }