001: /*
002: * @(#)ErrorsImplJDK13UTest.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.engine;
028:
029: import org.easymock.EasyMock;
030: import org.easymock.MockControl;
031: import net.sourceforge.groboutils.junit.v1.iftc.*;
032: import junit.framework.Test;
033: import junit.framework.TestCase;
034: import junit.framework.TestSuite;
035:
036: import net.sourceforge.groboutils.mbtf.v1.*;
037:
038: /**
039: * Tests the ErrorsImpl class.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @version $Date: 2003/05/29 13:05:55 $
043: * @since March 21, 2002
044: */
045: public class ErrorsImplJDK13UTest extends TestCase {
046: //-------------------------------------------------------------------------
047: // Standard JUnit Class-specific declarations
048:
049: private static final Class THIS_CLASS = ErrorsImplJDK13UTest.class;
050:
051: public ErrorsImplJDK13UTest(String name) {
052: super (name);
053: }
054:
055: //-------------------------------------------------------------------------
056: // setup
057:
058: private MockControl phControl;
059: private IPathHistory mockPH;
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: this .phControl = EasyMock.controlFor(IPathHistory.class);
070: this .mockPH = (IPathHistory) this .phControl.getMock();
071: }
072:
073: //-------------------------------------------------------------------------
074: // Tests
075:
076: public void testConstructor1() {
077: ErrorsImpl ei = new ErrorsImpl();
078: assertEquals("# of errors not zero", ei.getErrors().length, 0);
079: assertEquals("# of warnings not zero", ei.getWarnings().length,
080: 0);
081: assertTrue("default path halt state wrong", !ei.isHaltPath());
082: assertTrue("default test halt state wrong", !ei.isHaltTests());
083: }
084:
085: public void testHalt1() {
086: ErrorsImpl ei = new ErrorsImpl();
087: String msg = "msg";
088:
089: try {
090: ei.halt(msg);
091: fail("did not throw exception");
092: } catch (TestHaltRuntimeException thre) {
093: // check exception?
094: }
095:
096: assertErrors(ei, msg, null, null);
097: assertTrue("path halt not set right", ei.isHaltPath());
098: assertTrue("test halt not set right", ei.isHaltTests());
099: }
100:
101: public void testHalt2() {
102: String msg = "msg";
103: ErrorsImpl ei = new ErrorsImpl();
104: this .mockPH.copy();
105: this .phControl.setReturnValue(this .mockPH, 1);
106: this .phControl.activate();
107:
108: ei.setCurrentPathHistory(this .mockPH);
109: try {
110: ei.halt(msg);
111: fail("did not throw exception");
112: } catch (TestHaltRuntimeException thre) {
113: // check exception?
114: }
115: assertTrue("path halt not set right", ei.isHaltPath());
116: assertTrue("test halt not set right", ei.isHaltTests());
117: assertErrors(ei, msg, this .mockPH, null);
118:
119: this .phControl.verify();
120: }
121:
122: public void testAddFailure1() {
123: String msg = "msg 2";
124: ErrorsImpl ei = new ErrorsImpl();
125:
126: ei.addFailure(msg);
127:
128: assertTrue("path halt not set right", ei.isHaltPath());
129: assertTrue("test halt not set right", !ei.isHaltTests());
130: assertErrors(ei, msg, null, null);
131: }
132:
133: public void testAddFailure2() {
134: String msg = "msg < >";
135: ErrorsImpl ei = new ErrorsImpl();
136: this .mockPH.copy();
137: this .phControl.setReturnValue(this .mockPH, 1);
138: this .phControl.activate();
139:
140: ei.setCurrentPathHistory(this .mockPH);
141: ei.addFailure(msg);
142:
143: assertTrue("path halt not set right", ei.isHaltPath());
144: assertTrue("test halt not set right", !ei.isHaltTests());
145: assertErrors(ei, msg, this .mockPH, null);
146:
147: this .phControl.verify();
148: }
149:
150: public void testAddFailure3() {
151: String msg = "msg 2";
152: Throwable t = new Throwable("ignore");
153: ErrorsImpl ei = new ErrorsImpl();
154:
155: ei.addFailure(msg, t);
156:
157: assertTrue("path halt not set right", ei.isHaltPath());
158: assertTrue("test halt not set right", !ei.isHaltTests());
159: assertErrors(ei, msg, null, t);
160: }
161:
162: public void testAddFailure4() {
163: String msg = "msg < >";
164: Throwable t = new Throwable("ignore");
165: ErrorsImpl ei = new ErrorsImpl();
166: this .mockPH.copy();
167: this .phControl.setReturnValue(this .mockPH, 1);
168: this .phControl.activate();
169:
170: ei.setCurrentPathHistory(this .mockPH);
171: ei.addFailure(msg, t);
172:
173: assertTrue("path halt not set right", ei.isHaltPath());
174: assertTrue("test halt not set right", !ei.isHaltTests());
175: assertErrors(ei, msg, this .mockPH, t);
176:
177: this .phControl.verify();
178: }
179:
180: public void testAddError1() {
181: String msg = "msg 2";
182: ErrorsImpl ei = new ErrorsImpl();
183:
184: ei.addError(msg);
185:
186: assertTrue("path halt not set right", !ei.isHaltPath());
187: assertTrue("test halt not set right", !ei.isHaltTests());
188: assertErrors(ei, msg, null, null);
189: }
190:
191: public void testAddError2() {
192: String msg = "msg < >";
193: ErrorsImpl ei = new ErrorsImpl();
194: this .mockPH.copy();
195: this .phControl.setReturnValue(this .mockPH, 1);
196: this .phControl.activate();
197:
198: ei.setCurrentPathHistory(this .mockPH);
199: ei.addError(msg);
200:
201: assertTrue("path halt not set right", !ei.isHaltPath());
202: assertTrue("test halt not set right", !ei.isHaltTests());
203: assertErrors(ei, msg, this .mockPH, null);
204:
205: this .phControl.verify();
206: }
207:
208: public void testAddError3() {
209: String msg = "msg 2";
210: Throwable t = new Throwable("ignore");
211: ErrorsImpl ei = new ErrorsImpl();
212:
213: ei.addError(msg, t);
214:
215: assertTrue("path halt not set right", !ei.isHaltPath());
216: assertTrue("test halt not set right", !ei.isHaltTests());
217: assertErrors(ei, msg, null, t);
218: }
219:
220: public void testAddError4() {
221: String msg = "msg < >";
222: Throwable t = new Throwable("ignore");
223: ErrorsImpl ei = new ErrorsImpl();
224: this .mockPH.copy();
225: this .phControl.setReturnValue(this .mockPH, 1);
226: this .phControl.activate();
227:
228: ei.setCurrentPathHistory(this .mockPH);
229: ei.addError(msg, t);
230:
231: assertTrue("path halt not set right", !ei.isHaltPath());
232: assertTrue("test halt not set right", !ei.isHaltTests());
233: assertErrors(ei, msg, this .mockPH, t);
234:
235: this .phControl.verify();
236: }
237:
238: //-------------------------------------------------------------------------
239: // Helpers
240:
241: protected void assertErrors(ErrorsImpl ei, String msg,
242: IPathHistory hist, Throwable t) {
243: IError e[] = ei.getErrors();
244: assertErrorType(e, msg, hist, t);
245: }
246:
247: protected void assertErrorType(IError[] e, String msg,
248: IPathHistory hist, Throwable t) {
249: assertNotNull("error array is null", e);
250: assertEquals("did not add error correctly", e.length, 1);
251: assertNotNull("error contents are null", e[0]);
252: assertEquals("path history is not correct", e[0]
253: .getPathHistory(), hist);
254: assertEquals("throwable is not correct", e[0].getThrowable(), t);
255: assertEquals("message not right.", e[0].getMessage(), msg);
256: }
257:
258: //-------------------------------------------------------------------------
259: // Standard JUnit declarations
260:
261: public static Test suite() {
262: InterfaceTestSuite suite = IErrorsUTestI.suite();
263:
264: // Test the implementation's interface conformity.
265: suite.addFactory(new CxFactory("A") {
266: public Object createImplObject() {
267: return new ErrorsImpl();
268: }
269: });
270: return suite;
271: }
272:
273: public static void main(String[] args) {
274: String[] name = { THIS_CLASS.getName() };
275:
276: // junit.textui.TestRunner.main( name );
277: // junit.swingui.TestRunner.main( name );
278:
279: junit.textui.TestRunner.main(name);
280: }
281:
282: /**
283: *
284: * @exception Exception thrown under any exceptional condition.
285: */
286: protected void tearDown() throws Exception {
287: // tear ourself down
288:
289: super.tearDown();
290: }
291: }
|