KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > mbtf > v1 > assembler > AsmblStateUTest


1 /*
2  * @(#)AsmblStateUTest.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

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 /**
42  * Tests the AsmblState class.
43  *
44  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
45  * @version $Date: 2003/02/10 22:52:28 $
46  * @since June 17, 2002
47  */

48 public class AsmblStateUTest extends TestCase
49 {
50     //-------------------------------------------------------------------------
51
// Standard JUnit Class-specific declarations
52

53     private static final Class JavaDoc THIS_CLASS = AsmblStateUTest.class;
54     
55     public AsmblStateUTest( String JavaDoc name )
56     {
57         super( name );
58     }
59
60     
61     //-------------------------------------------------------------------------
62
// setup
63

64     /**
65      *
66      * @exception Exception thrown under any exceptional condition.
67      */

68     protected void setUp() throws Exception JavaDoc
69     {
70         super.setUp();
71         
72         // set ourself up
73
}
74
75
76     //-------------------------------------------------------------------------
77
// Tests
78

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 JavaDoc[] 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 JavaDoc transName = "t1";
151         AsmblState at = new AsmblState();
152         at.addTransitionName( transName );
153         String JavaDoc[] 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 JavaDoc iae)
179         {
180             // check reason
181
}
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     //-------------------------------------------------------------------------
234
// Helpers
235

236     
237     //-------------------------------------------------------------------------
238
// Standard JUnit declarations
239

240     
241     public static Test suite()
242     {
243         TestSuite suite = new TestSuite( THIS_CLASS );
244         
245         // Test the implementation's interface conformity.
246
/*
247         suite.addTest( IxUTestI.suite(
248             new ImplementationCreator[] {
249                 new ImplementationCreator() {
250                     public Object createImplementedObject() {
251                         // XXXXXXXXXXXXXXXXXXXXXXXX
252                     }
253                 },
254             } ) );
255         */

256         return suite;
257     }
258     
259     public static void main( String JavaDoc[] args )
260     {
261         String JavaDoc[] name = { THIS_CLASS.getName() };
262         
263         // junit.textui.TestRunner.main( name );
264
// junit.swingui.TestRunner.main( name );
265

266         junit.textui.TestRunner.main( name );
267     }
268     
269     
270     /**
271      *
272      * @exception Exception thrown under any exceptional condition.
273      */

274     protected void tearDown() throws Exception JavaDoc
275     {
276         // tear ourself down
277

278         super.tearDown();
279     }
280 }
281
282
Popular Tags