KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > autodoc > v1 > testserver > DefaultMonitorUTest


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

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

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

62     /**
63      *
64      * @exception Exception thrown under any exceptional condition.
65      */

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

77     
78     public void testConstructor1()
79     {
80         try
81         {
82             new DefaultMonitor( null, null );
83             fail("Did not throw an IllegalArgumentException");
84         }
85         catch (IllegalArgumentException JavaDoc ise)
86         {
87             // test error?
88
}
89     }
90     
91     
92     public void testConstructor2()
93     {
94         Server s = new MyServer();
95         try
96         {
97             new DefaultMonitor( s, null );
98             fail("Did not throw an IllegalArgumentException");
99         }
100         catch (IllegalArgumentException JavaDoc ise)
101         {
102             // test error?
103
}
104     }
105     
106     
107     public void testConstructor3()
108     {
109         TestDataFactory tdf = new MyTDFactory();
110         try
111         {
112             new DefaultMonitor( null, tdf );
113             fail("Did not throw an IllegalArgumentException");
114         }
115         catch (IllegalArgumentException JavaDoc ise)
116         {
117             // test error?
118
}
119     }
120     
121     
122     public void testRemoveInfoOnSend1()
123     {
124         DefaultMonitor dm = new DefaultMonitor(
125             new MyServer(), new MyTDFactory() );
126         TestInfo ti = new DefaultTestInfo( "A", "b" );
127         dm.addTestData( ti );
128         dm.sendTestData( ti );
129         try
130         {
131             dm.getTestData( ti );
132             fail( "Did not throw an IllegalStateException." );
133         }
134         catch (IllegalStateException JavaDoc ise)
135         {
136             // test exception
137
}
138     }
139     
140     
141     
142     
143     //-------------------------------------------------------------------------
144
// Helpers
145

146     
147     protected static class MyServer implements Server
148     {
149         public void addTestData( TestData td )
150         {
151             // do nothing
152
}
153     }
154     
155     
156     protected static class MyTestData implements TestData
157     {
158         TestInfo info;
159         public MyTestData( TestInfo ti )
160         {
161             this.info = ti;
162         }
163         public TestInfo getTestInfo()
164         {
165             return this.info;
166         }
167     }
168     
169     
170     protected static class MyTDFactory implements TestDataFactory
171     {
172         public TestData createTestData( TestInfo info )
173         {
174             return new MyTestData( info );
175         }
176     }
177
178     
179     
180     //-------------------------------------------------------------------------
181
// Standard JUnit declarations
182

183     
184     public static Test suite()
185     {
186         InterfaceTestSuite suite = MonitorUTestI.suite();
187         suite.addTestSuite( THIS_CLASS );
188         suite.addFactory( new CxFactory( "A" ) {
189             public Object JavaDoc createImplObject() {
190                 Server s = new MyServer();
191                 TestDataFactory tdf = new MyTDFactory();
192                 return new DefaultMonitor( s, tdf );
193             }
194         } );
195         
196         return suite;
197     }
198     
199     public static void main( String JavaDoc[] args )
200     {
201         String JavaDoc[] name = { THIS_CLASS.getName() };
202         
203         // junit.textui.TestRunner.main( name );
204
// junit.swingui.TestRunner.main( name );
205

206         junit.textui.TestRunner.main( name );
207     }
208     
209     
210     /**
211      *
212      * @exception Exception thrown under any exceptional condition.
213      */

214     protected void tearDown() throws Exception JavaDoc
215     {
216         // tear ourself down
217

218         super.tearDown();
219     }
220 }
221
222
Popular Tags