KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > mbtf > v1 > engine > ErrorsImplJDK13UTest


1 /*
2  * @(#)ErrorsImplJDK13UTest.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.engine;
28
29 import org.easymock.EasyMock;
30 import org.easymock.MockControl;
31 import net.sourceforge.groboutils.junit.v1.iftc.*;
32 import junit.framework.Test;
33 import junit.framework.TestCase;
34 import junit.framework.TestSuite;
35
36 import net.sourceforge.groboutils.mbtf.v1.*;
37
38 /**
39  * Tests the ErrorsImpl class.
40  *
41  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
42  * @version $Date: 2003/05/29 13:05:55 $
43  * @since March 21, 2002
44  */

45 public class ErrorsImplJDK13UTest extends TestCase
46 {
47     //-------------------------------------------------------------------------
48
// Standard JUnit Class-specific declarations
49

50     private static final Class JavaDoc THIS_CLASS = ErrorsImplJDK13UTest.class;
51     
52     public ErrorsImplJDK13UTest( String JavaDoc name )
53     {
54         super( name );
55     }
56
57     
58     //-------------------------------------------------------------------------
59
// setup
60

61     private MockControl phControl;
62     private IPathHistory mockPH;
63
64     
65     /**
66      *
67      * @exception Exception thrown under any exceptional condition.
68      */

69     protected void setUp() throws Exception JavaDoc
70     {
71         super.setUp();
72         
73         // set ourself up
74
this.phControl = EasyMock.controlFor( IPathHistory.class );
75         this.mockPH = (IPathHistory)this.phControl.getMock();
76     }
77
78
79     //-------------------------------------------------------------------------
80
// Tests
81

82     
83     public void testConstructor1()
84     {
85         ErrorsImpl ei = new ErrorsImpl();
86         assertEquals(
87             "# of errors not zero",
88             ei.getErrors().length,
89             0 );
90         assertEquals(
91             "# of warnings not zero",
92             ei.getWarnings().length,
93             0 );
94         assertTrue(
95             "default path halt state wrong",
96             !ei.isHaltPath() );
97         assertTrue(
98             "default test halt state wrong",
99             !ei.isHaltTests() );
100     }
101     
102     
103     public void testHalt1()
104     {
105         ErrorsImpl ei = new ErrorsImpl();
106         String JavaDoc msg = "msg";
107         
108         try
109         {
110             ei.halt( msg );
111             fail("did not throw exception");
112         }
113         catch (TestHaltRuntimeException thre)
114         {
115             // check exception?
116
}
117         
118         assertErrors( ei, msg, null, null );
119         assertTrue(
120             "path halt not set right",
121             ei.isHaltPath() );
122         assertTrue(
123             "test halt not set right",
124             ei.isHaltTests() );
125     }
126     
127     
128     public void testHalt2()
129     {
130         String JavaDoc msg = "msg";
131         ErrorsImpl ei = new ErrorsImpl();
132         this.mockPH.copy();
133         this.phControl.setReturnValue( this.mockPH, 1 );
134         this.phControl.activate();
135         
136         
137         ei.setCurrentPathHistory( this.mockPH );
138         try
139         {
140             ei.halt( msg );
141             fail("did not throw exception");
142         }
143         catch (TestHaltRuntimeException thre)
144         {
145             // check exception?
146
}
147         assertTrue(
148             "path halt not set right",
149             ei.isHaltPath() );
150         assertTrue(
151             "test halt not set right",
152             ei.isHaltTests() );
153         assertErrors( ei, msg, this.mockPH, null );
154         
155         this.phControl.verify();
156     }
157     
158     
159     public void testAddFailure1()
160     {
161         String JavaDoc msg = "msg 2";
162         ErrorsImpl ei = new ErrorsImpl();
163         
164         ei.addFailure( msg );
165         
166         assertTrue(
167             "path halt not set right",
168             ei.isHaltPath() );
169         assertTrue(
170             "test halt not set right",
171             !ei.isHaltTests() );
172         assertErrors( ei, msg, null, null );
173     }
174     
175     
176     public void testAddFailure2()
177     {
178         String JavaDoc msg = "msg < >";
179         ErrorsImpl ei = new ErrorsImpl();
180         this.mockPH.copy();
181         this.phControl.setReturnValue( this.mockPH, 1 );
182         this.phControl.activate();
183         
184         
185         ei.setCurrentPathHistory( this.mockPH );
186         ei.addFailure( msg );
187         
188         assertTrue(
189             "path halt not set right",
190             ei.isHaltPath() );
191         assertTrue(
192             "test halt not set right",
193             !ei.isHaltTests() );
194         assertErrors( ei, msg, this.mockPH, null );
195         
196         this.phControl.verify();
197     }
198     
199     
200     public void testAddFailure3()
201     {
202         String JavaDoc msg = "msg 2";
203         Throwable JavaDoc t = new Throwable JavaDoc("ignore");
204         ErrorsImpl ei = new ErrorsImpl();
205         
206         ei.addFailure( msg, t );
207         
208         assertTrue(
209             "path halt not set right",
210             ei.isHaltPath() );
211         assertTrue(
212             "test halt not set right",
213             !ei.isHaltTests() );
214         assertErrors( ei, msg, null, t );
215     }
216     
217     
218     public void testAddFailure4()
219     {
220         String JavaDoc msg = "msg < >";
221         Throwable JavaDoc t = new Throwable JavaDoc("ignore");
222         ErrorsImpl ei = new ErrorsImpl();
223         this.mockPH.copy();
224         this.phControl.setReturnValue( this.mockPH, 1 );
225         this.phControl.activate();
226         
227         
228         ei.setCurrentPathHistory( this.mockPH );
229         ei.addFailure( msg, t );
230         
231         assertTrue(
232             "path halt not set right",
233             ei.isHaltPath() );
234         assertTrue(
235             "test halt not set right",
236             !ei.isHaltTests() );
237         assertErrors( ei, msg, this.mockPH, t );
238         
239         this.phControl.verify();
240     }
241
242
243     
244     
245     public void testAddError1()
246     {
247         String JavaDoc msg = "msg 2";
248         ErrorsImpl ei = new ErrorsImpl();
249         
250         ei.addError( msg );
251         
252         assertTrue(
253             "path halt not set right",
254             !ei.isHaltPath() );
255         assertTrue(
256             "test halt not set right",
257             !ei.isHaltTests() );
258         assertErrors( ei, msg, null, null );
259     }
260     
261     
262     public void testAddError2()
263     {
264         String JavaDoc msg = "msg < >";
265         ErrorsImpl ei = new ErrorsImpl();
266         this.mockPH.copy();
267         this.phControl.setReturnValue( this.mockPH, 1 );
268         this.phControl.activate();
269         
270         
271         ei.setCurrentPathHistory( this.mockPH );
272         ei.addError( msg );
273         
274         assertTrue(
275             "path halt not set right",
276             !ei.isHaltPath() );
277         assertTrue(
278             "test halt not set right",
279             !ei.isHaltTests() );
280         assertErrors( ei, msg, this.mockPH, null );
281         
282         this.phControl.verify();
283     }
284     
285     
286     public void testAddError3()
287     {
288         String JavaDoc msg = "msg 2";
289         Throwable JavaDoc t = new Throwable JavaDoc("ignore");
290         ErrorsImpl ei = new ErrorsImpl();
291         
292         ei.addError( msg, t );
293         
294         assertTrue(
295             "path halt not set right",
296             !ei.isHaltPath() );
297         assertTrue(
298             "test halt not set right",
299             !ei.isHaltTests() );
300         assertErrors( ei, msg, null, t );
301     }
302     
303     
304     public void testAddError4()
305     {
306         String JavaDoc msg = "msg < >";
307         Throwable JavaDoc t = new Throwable JavaDoc("ignore");
308         ErrorsImpl ei = new ErrorsImpl();
309         this.mockPH.copy();
310         this.phControl.setReturnValue( this.mockPH, 1 );
311         this.phControl.activate();
312         
313         
314         ei.setCurrentPathHistory( this.mockPH );
315         ei.addError( msg, t );
316         
317         assertTrue(
318             "path halt not set right",
319             !ei.isHaltPath() );
320         assertTrue(
321             "test halt not set right",
322             !ei.isHaltTests() );
323         assertErrors( ei, msg, this.mockPH, t );
324         
325         this.phControl.verify();
326     }
327     
328     
329     
330     //-------------------------------------------------------------------------
331
// Helpers
332

333     
334     protected void assertErrors( ErrorsImpl ei, String JavaDoc msg, IPathHistory hist,
335             Throwable JavaDoc t )
336     {
337         IError e[] = ei.getErrors();
338         assertErrorType( e, msg, hist, t );
339     }
340     
341     
342     protected void assertErrorType( IError[] e, String JavaDoc msg,
343             IPathHistory hist, Throwable JavaDoc t )
344     {
345         assertNotNull(
346             "error array is null",
347             e );
348         assertEquals(
349             "did not add error correctly",
350             e.length,
351             1 );
352         assertNotNull(
353             "error contents are null",
354             e[0] );
355         assertEquals(
356             "path history is not correct",
357             e[0].getPathHistory(),
358             hist );
359         assertEquals(
360             "throwable is not correct",
361             e[0].getThrowable(),
362             t );
363         assertEquals(
364             "message not right.",
365             e[0].getMessage(),
366             msg );
367     }
368     
369     //-------------------------------------------------------------------------
370
// Standard JUnit declarations
371

372     
373     public static Test suite()
374     {
375         InterfaceTestSuite suite = IErrorsUTestI.suite();
376         
377         // Test the implementation's interface conformity.
378
suite.addFactory( new CxFactory( "A" ) {
379             public Object JavaDoc createImplObject() {
380                 return new ErrorsImpl();
381             }
382         } );
383         return suite;
384     }
385     
386     public static void main( String JavaDoc[] args )
387     {
388         String JavaDoc[] name = { THIS_CLASS.getName() };
389         
390         // junit.textui.TestRunner.main( name );
391
// junit.swingui.TestRunner.main( name );
392

393         junit.textui.TestRunner.main( name );
394     }
395     
396     
397     /**
398      *
399      * @exception Exception thrown under any exceptional condition.
400      */

401     protected void tearDown() throws Exception JavaDoc
402     {
403         // tear ourself down
404

405         super.tearDown();
406     }
407 }
408
Popular Tags