001: /*
002: * @(#)AsmblTransitionUTest.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.ITransition;
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 AsmblTransition 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 AsmblTransitionUTest extends TestCase {
049: //-------------------------------------------------------------------------
050: // Standard JUnit Class-specific declarations
051:
052: private static final Class THIS_CLASS = AsmblTransitionUTest.class;
053:
054: public AsmblTransitionUTest(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 AsmblTransition();
076: }
077:
078: public void testAddValidate1() {
079: AsmblTransition at = new AsmblTransition();
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: AsmblTransition at = new AsmblTransition();
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 testGetTransition1() {
107: AsmblTransition at = new AsmblTransition();
108: try {
109: at.getTransition();
110: fail("did not throw IllegalArgumentException");
111: } catch (IllegalArgumentException iae) {
112: // test exception
113: }
114: }
115:
116: public void testGetTransition2() {
117: AsmblTransition at = new AsmblTransition();
118: at.setName("trans");
119: at.setNextStateName("state");
120: IAction act = new MyAction();
121: at.setAction(act);
122: ITransition t = at.getTransition();
123: assertNotNull("get transition returned null.", t);
124: assertEquals("wrong name.", "trans", t.getName());
125: assertEquals("wrong action.", act, t.getAction());
126:
127: try {
128: t.getDestinationState();
129: fail("did not throw IllegalStateException");
130: } catch (IllegalStateException e) {
131: // test exception
132: }
133: }
134:
135: //-------------------------------------------------------------------------
136: // Helpers
137:
138: //-------------------------------------------------------------------------
139: // Standard JUnit declarations
140:
141: public static Test suite() {
142: TestSuite suite = new TestSuite(THIS_CLASS);
143:
144: // Test the implementation's interface conformity.
145: /*
146: suite.addTest( IxUTestI.suite(
147: new ImplementationCreator[] {
148: new ImplementationCreator() {
149: public Object createImplementedObject() {
150: // XXXXXXXXXXXXXXXXXXXXXXXX
151: }
152: },
153: } ) );
154: */
155: return suite;
156: }
157:
158: public static void main(String[] args) {
159: String[] name = { THIS_CLASS.getName() };
160:
161: // junit.textui.TestRunner.main( name );
162: // junit.swingui.TestRunner.main( name );
163:
164: junit.textui.TestRunner.main(name);
165: }
166:
167: /**
168: *
169: * @exception Exception thrown under any exceptional condition.
170: */
171: protected void tearDown() throws Exception {
172: // tear ourself down
173:
174: super.tearDown();
175: }
176: }
|