View Javadoc
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.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 }