1 26 27 package net.sourceforge.groboutils.mbtf.v1.assembler; 28 29 import org.easymock.EasyMock; 30 import org.easymock.MockControl; 31 import junit.framework.Test; 32 import junit.framework.TestCase; 33 import junit.framework.TestSuite; 34 35 import net.sourceforge.groboutils.mbtf.v1.IState; 36 import net.sourceforge.groboutils.mbtf.v1.IValidate; 37 import net.sourceforge.groboutils.mbtf.v1.ISystem; 38 import net.sourceforge.groboutils.mbtf.v1.IErrors; 39 import net.sourceforge.groboutils.mbtf.v1.IAction; 40 41 48 public class AsmblStateUTest extends TestCase 49 { 50 53 private static final Class THIS_CLASS = AsmblStateUTest.class; 54 55 public AsmblStateUTest( String name ) 56 { 57 super( name ); 58 } 59 60 61 64 68 protected void setUp() throws Exception 69 { 70 super.setUp(); 71 72 } 74 75 76 79 80 public void testConstructor1() 81 { 82 new AsmblState(); 83 } 84 85 86 public void testAddValidate1() 87 { 88 AsmblState at = new AsmblState(); 89 at.addValidate( null ); 90 IValidate[] v = at.getValidates(); 91 assertNotNull( 92 "validates returned null.", 93 v ); 94 assertEquals( 95 "validates size not right.", 96 0, 97 v.length ); 98 } 99 100 101 private static class MyValidate implements IValidate 102 { 103 public void validate( ISystem s, IErrors e ) {} 104 } 105 106 107 private static class MyAction implements IAction 108 { 109 public void performAction( ISystem s, IErrors e ) {} 110 } 111 112 113 public void testAddValidate2() 114 { 115 IValidate ov = new MyValidate(); 116 AsmblState at = new AsmblState(); 117 at.addValidate( ov ); 118 IValidate[] v = at.getValidates(); 119 assertNotNull( 120 "validates returned null.", 121 v ); 122 assertEquals( 123 "validates size not right.", 124 1, 125 v.length ); 126 assertEquals( 127 "validates inserted not returned.", 128 ov, 129 v[0] ); 130 } 131 132 133 public void testAddTransitionName1() 134 { 135 AsmblState at = new AsmblState(); 136 at.addTransitionName( null ); 137 String [] v = at.getTransitionNames(); 138 assertNotNull( 139 "trans names returned null.", 140 v ); 141 assertEquals( 142 "trans names size not right.", 143 0, 144 v.length ); 145 } 146 147 148 public void testAddTransitionName2() 149 { 150 String transName = "t1"; 151 AsmblState at = new AsmblState(); 152 at.addTransitionName( transName ); 153 String [] v = at.getTransitionNames(); 154 assertNotNull( 155 "trans names returned null.", 156 v ); 157 assertEquals( 158 "trans names size not right.", 159 1, 160 v.length ); 161 assertEquals( 162 "not same name as passed into add.", 163 transName, 164 v[0] ); 165 } 166 167 168 public void testCreateState1() 169 { 170 AsmblState at = new AsmblState(); 171 AsmblTransitionSet ats = new AsmblTransitionSet(); 172 173 try 174 { 175 IState state = at.createState( ats ); 176 fail("did not throw IllegalArgumentException"); 177 } 178 catch (IllegalArgumentException iae) 179 { 180 } 182 } 183 184 185 public void testCreateState2() 186 { 187 AsmblState as = new AsmblState(); 188 as.setName( "state" ); 189 AsmblTransitionSet ats = new AsmblTransitionSet(); 190 191 IState state = as.createState( ats ); 192 assertNotNull( 193 "returned null.", 194 state ); 195 assertEquals( 196 "wrong state name.", 197 "state", 198 as.getName() ); 199 } 200 201 202 public void testCreateState3() 203 { 204 AsmblState as = new AsmblState(); 205 as.setName( "state" ); 206 as.addTransitionName( "trans" ); 207 AsmblTransition at = new AsmblTransition(); 208 at.setName( "trans" ); 209 at.setNextStateName( "state" ); 210 at.setAction( new MyAction() ); 211 AsmblTransitionSet ats = new AsmblTransitionSet(); 212 ats.addTransition( at ); 213 214 IState state = as.createState( ats ); 215 assertNotNull( 216 "returned null.", 217 state ); 218 assertEquals( 219 "wrong name for state.", 220 "state", 221 state.getName() ); 222 assertEquals( 223 "wrong transition length.", 224 1, 225 state.getTransitions().length ); 226 assertEquals( 227 "wrong validates length.", 228 0, 229 state.getValidates().length ); 230 } 231 232 233 236 237 240 241 public static Test suite() 242 { 243 TestSuite suite = new TestSuite( THIS_CLASS ); 244 245 256 return suite; 257 } 258 259 public static void main( String [] args ) 260 { 261 String [] name = { THIS_CLASS.getName() }; 262 263 266 junit.textui.TestRunner.main( name ); 267 } 268 269 270 274 protected void tearDown() throws Exception 275 { 276 278 super.tearDown(); 279 } 280 } 281 282 | Popular Tags |