001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.scxml2; 018 019import java.util.Set; 020 021import org.apache.commons.scxml2.model.EnterableState; 022import org.apache.commons.scxml2.model.Final; 023import org.apache.commons.scxml2.model.State; 024import org.junit.Assert; 025import org.junit.Before; 026import org.junit.Test; 027 028public class StatusTest { 029 030 private StateConfiguration stateConfiguration; 031 private Status status; 032 033 @Before 034 public void setUp() { 035 stateConfiguration = new StateConfiguration(); 036 status = new Status(stateConfiguration); 037 } 038 039 @Test 040 public void testIsFinalStateFalse() { 041 State state = new State(); 042 043 stateConfiguration.enterState(state); 044 045 Assert.assertFalse(status.isFinal()); 046 } 047 048 @Test 049 public void testIsFinalStateHasParent() { 050 Final state = new Final(); 051 state.setParent(new State()); 052 053 stateConfiguration.enterState(state); 054 055 Assert.assertFalse(status.isFinal()); 056 } 057 058 @Test 059 public void testIsFinalState() { 060 Final state = new Final(); 061 062 stateConfiguration.enterState(state); 063 064 Assert.assertTrue(status.isFinal()); 065 } 066 067 @Test 068 public void testGetAllStatesEmptyStatus() { 069 070 Set<EnterableState> returnValue = status.getActiveStates(); 071 072 Assert.assertEquals(0, returnValue.size()); 073 } 074 075 @Test 076 public void testGetAllStatesContainsParent() { 077 State parent = new State(); 078 parent.setId("0"); 079 stateConfiguration.enterState(parent); 080 State state = new State(); 081 state.setId("1"); 082 state.setParent(parent); 083 stateConfiguration.enterState(state); 084 085 Set<EnterableState> returnValue = status.getActiveStates(); 086 087 Assert.assertEquals(2, returnValue.size()); 088 } 089 090 @Test 091 public void testIsInState() { 092 State parent = new State(); 093 parent.setId("0"); 094 stateConfiguration.enterState(parent); 095 State state = new State(); 096 state.setId("1"); 097 state.setParent(parent); 098 stateConfiguration.enterState(state); 099 Assert.assertTrue(status.isInState("0")); 100 Assert.assertTrue(status.isInState("1")); 101 Assert.assertFalse(status.isInState("2")); 102 } 103}