    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.List;
    20
    21  import junit.framework.Test;
    22  import junit.framework.TestCase;
    23  import junit.framework.TestSuite;
    24
    25  public class StateTest extends TestCase {
    26
    27      public StateTest(String testName) {
    28          super(testName);
    29      }
    30
    31      public static Test suite() {
    32          return new TestSuite(StateTest.class);
    33      }
    34
    35      public static void main(String args[]) {
    36          String[] testCaseName = { StateTest.class.getName()};
    37          junit.textui.TestRunner.main(testCaseName);
    38      }
    39
    40      private State state;
    41
    42      public void setUp() {
    43          state = new State();
    44      }
    45
    46      public void testGetTransitionsListNull() {
    47          assertNull(state.getTransitionsList("event"));
    48      }
    49
    50      public void testGetTransitionsList() {
    51
    52          state.getTransitionsList().add(new Transition());
    53
    54          assertNotNull(state.getTransitionsList(null));
    55      }
    56
    57      public void testAddTransitionDoesNotContainKey() {
    58          Transition transition = new Transition();
    59          transition.setEvent("event");
    60
    61          state.addTransition(transition);
    62
    63          List events = (List)state.getTransitionsList("event");
    64
    65          assertEquals(1, events.size());
    66          assertEquals("event", ((Transition)events.get(0)).getEvent());
    67      }
    68
    69      public void testAddTransitionContainKey() {
    70          Transition transition1 = new Transition();
    71          transition1.setEvent("event");
    72
    73          Transition transition2 = new Transition();
    74          transition2.setEvent("event");
    75
    76          state.addTransition(transition1);
    77          state.addTransition(transition2);
    78
    79          List events = (List)state.getTransitionsList("event");
    80
    81          assertEquals(2, events.size());
    82      }
    83
    84      public void testGetTransitionList() {
    85          Transition transition1 = new Transition();
    86          transition1.setEvent("event");
    87
    88          Transition transition2 = new Transition();
    89          transition2.setEvent("event");
    90
    91          state.addTransition(transition1);
    92          state.addTransition(transition2);
    93
    94          List events = state.getTransitionsList();
    95
    96          assertEquals(2, events.size());
    97      }
    98
    99      public void testHasHistoryEmpty() {
    100         assertFalse(state.hasHistory());
    101     }
    102
    103     public void testHasHistory() {
    104         History history = new History();
    105
    106         state.addHistory(history);
    107
    108         assertTrue(state.hasHistory());
    109     }
    110
    111     public void testIsSimple() {
    112         assertTrue(state.isSimple());
    113     }
    114
    115     public void testIsSimpleHasChildren() {
    116         State state1 = new State();
    117
    118         // redundant cast to remove deprecation warning
    119         // could be removed in v1.0
    120         state.addChild((TransitionTarget) state1);
    121
    122         assertFalse(state.isSimple());
    123     }
    124
    125     public void testIsCompositeFalse() {
    126         assertFalse(state.isComposite());
    127     }
    128
    129     public void testIsCompositeParallel() {
    130         State child = new State();
    131
    132         state.addChild((TransitionTarget) child);
    133
    134         assertTrue(state.isComposite());
    135     }
    136
    137     public void testIsCompositeHasChildren() {
    138         State state1 = new State();
    139
    140         // redundant cast to remove deprecation warning
    141         // could be removed in v1.0
    142         state.addChild((TransitionTarget) state1);
    143
    144         assertTrue(state.isComposite());
    145     }
    146
    147     public void testIsRegion() {
    148         state.setParent(new Parallel());
    149
    150         assertTrue(state.isRegion());
    151     }
    152
    153     public void testIsRegionNotParallel() {
    154         state.setParent(new State());
    155
    156         assertFalse(state.isRegion());
    157     }
    158
    159 }