001: /*
002: * @(#)AsmblStateUTest.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.mbtf.v1.assembler;
028:
029: import org.easymock.EasyMock;
030: import org.easymock.MockControl;
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034:
035: import net.sourceforge.groboutils.mbtf.v1.IState;
036: import net.sourceforge.groboutils.mbtf.v1.IValidate;
037: import net.sourceforge.groboutils.mbtf.v1.ISystem;
038: import net.sourceforge.groboutils.mbtf.v1.IErrors;
039: import net.sourceforge.groboutils.mbtf.v1.IAction;
040:
041: /**
042: * Tests the AsmblState class.
043: *
044: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
045: * @version $Date: 2003/02/10 22:52:28 $
046: * @since June 17, 2002
047: */
048: public class AsmblStateUTest extends TestCase {
049: //-------------------------------------------------------------------------
050: // Standard JUnit Class-specific declarations
051:
052: private static final Class THIS_CLASS = AsmblStateUTest.class;
053:
054: public AsmblStateUTest(String name) {
055: super (name);
056: }
057:
058: //-------------------------------------------------------------------------
059: // setup
060:
061: /**
062: *
063: * @exception Exception thrown under any exceptional condition.
064: */
065: protected void setUp() throws Exception {
066: super .setUp();
067:
068: // set ourself up
069: }
070:
071: //-------------------------------------------------------------------------
072: // Tests
073:
074: public void testConstructor1() {
075: new AsmblState();
076: }
077:
078: public void testAddValidate1() {
079: AsmblState at = new AsmblState();
080: at.addValidate(null);
081: IValidate[] v = at.getValidates();
082: assertNotNull("validates returned null.", v);
083: assertEquals("validates size not right.", 0, v.length);
084: }
085:
086: private static class MyValidate implements IValidate {
087: public void validate(ISystem s, IErrors e) {
088: }
089: }
090:
091: private static class MyAction implements IAction {
092: public void performAction(ISystem s, IErrors e) {
093: }
094: }
095:
096: public void testAddValidate2() {
097: IValidate ov = new MyValidate();
098: AsmblState at = new AsmblState();
099: at.addValidate(ov);
100: IValidate[] v = at.getValidates();
101: assertNotNull("validates returned null.", v);
102: assertEquals("validates size not right.", 1, v.length);
103: assertEquals("validates inserted not returned.", ov, v[0]);
104: }
105:
106: public void testAddTransitionName1() {
107: AsmblState at = new AsmblState();
108: at.addTransitionName(null);
109: String[] v = at.getTransitionNames();
110: assertNotNull("trans names returned null.", v);
111: assertEquals("trans names size not right.", 0, v.length);
112: }
113:
114: public void testAddTransitionName2() {
115: String transName = "t1";
116: AsmblState at = new AsmblState();
117: at.addTransitionName(transName);
118: String[] v = at.getTransitionNames();
119: assertNotNull("trans names returned null.", v);
120: assertEquals("trans names size not right.", 1, v.length);
121: assertEquals("not same name as passed into add.", transName,
122: v[0]);
123: }
124:
125: public void testCreateState1() {
126: AsmblState at = new AsmblState();
127: AsmblTransitionSet ats = new AsmblTransitionSet();
128:
129: try {
130: IState state = at.createState(ats);
131: fail("did not throw IllegalArgumentException");
132: } catch (IllegalArgumentException iae) {
133: // check reason
134: }
135: }
136:
137: public void testCreateState2() {
138: AsmblState as = new AsmblState();
139: as.setName("state");
140: AsmblTransitionSet ats = new AsmblTransitionSet();
141:
142: IState state = as.createState(ats);
143: assertNotNull("returned null.", state);
144: assertEquals("wrong state name.", "state", as.getName());
145: }
146:
147: public void testCreateState3() {
148: AsmblState as = new AsmblState();
149: as.setName("state");
150: as.addTransitionName("trans");
151: AsmblTransition at = new AsmblTransition();
152: at.setName("trans");
153: at.setNextStateName("state");
154: at.setAction(new MyAction());
155: AsmblTransitionSet ats = new AsmblTransitionSet();
156: ats.addTransition(at);
157:
158: IState state = as.createState(ats);
159: assertNotNull("returned null.", state);
160: assertEquals("wrong name for state.", "state", state.getName());
161: assertEquals("wrong transition length.", 1, state
162: .getTransitions().length);
163: assertEquals("wrong validates length.", 0,
164: state.getValidates().length);
165: }
166:
167: //-------------------------------------------------------------------------
168: // Helpers
169:
170: //-------------------------------------------------------------------------
171: // Standard JUnit declarations
172:
173: public static Test suite() {
174: TestSuite suite = new TestSuite(THIS_CLASS);
175:
176: // Test the implementation's interface conformity.
177: /*
178: suite.addTest( IxUTestI.suite(
179: new ImplementationCreator[] {
180: new ImplementationCreator() {
181: public Object createImplementedObject() {
182: // XXXXXXXXXXXXXXXXXXXXXXXX
183: }
184: },
185: } ) );
186: */
187: return suite;
188: }
189:
190: public static void main(String[] args) {
191: String[] name = { THIS_CLASS.getName() };
192:
193: // junit.textui.TestRunner.main( name );
194: // junit.swingui.TestRunner.main( name );
195:
196: junit.textui.TestRunner.main(name);
197: }
198:
199: /**
200: *
201: * @exception Exception thrown under any exceptional condition.
202: */
203: protected void tearDown() throws Exception {
204: // tear ourself down
205:
206: super.tearDown();
207: }
208: }
|