KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > junit > v1 > iftc > CxFactoryUTest


1 /*
2  * @(#)CxFactoryUTest.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.junit.v1.iftc;
28
29 import org.easymock.EasyMock;
30 import org.easymock.MockControl;
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34
35
36 /**
37  * Tests the CxFactory class. Concrete test for an abstract class.
38  *
39  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
40  * @since October 30, 2002
41  * @version $Date: 2003/05/29 13:05:52 $
42  */

43 public class CxFactoryUTest extends TestCase
44 {
45     //-------------------------------------------------------------------------
46
// Standard JUnit Class-specific declarations
47

48     private static final Class JavaDoc THIS_CLASS = CxFactoryUTest.class;
49     private static final String JavaDoc TC = "CxFactoryUTest";
50     private static final org.apache.log4j.Logger LOG =
51         org.apache.log4j.Logger.getLogger( THIS_CLASS );
52     
53     public CxFactoryUTest( String JavaDoc name )
54     {
55         super( name );
56     }
57     
58     
59     // intentionally non-static inner class
60
public class MyCxFactory extends CxFactory
61     {
62         public MyCxFactory( String JavaDoc n )
63         {
64             super( n );
65         }
66         
67         public MyCxFactory( String JavaDoc n, boolean a )
68         {
69             super( n, a );
70         }
71         
72         public Object JavaDoc createImplObject()
73         {
74             return "";
75         }
76     }
77     
78     
79     // intentionally static inner class
80
public static class MyStaticCxFactory extends CxFactory
81     {
82         public MyStaticCxFactory( String JavaDoc n )
83         {
84             super( n );
85         }
86         
87         public MyStaticCxFactory( String JavaDoc n, boolean a )
88         {
89             super( n, a );
90         }
91         
92         public Object JavaDoc createImplObject()
93         {
94             return "";
95         }
96     }
97     
98
99     //-------------------------------------------------------------------------
100
// Tests
101

102     
103     
104     
105     public void testToString1()
106     {
107         // try with a named inner class.
108
CxFactory cf = new MyCxFactory( "1" );
109         assertEquals(
110             "Returned unexpected factory name.",
111             "1",
112             cf.toString() );
113     }
114     
115     
116     public void testToString1b()
117     {
118         // try with a named inner class.
119
CxFactory cf = new MyCxFactory( "1b", false );
120         assertEquals(
121             "Returned unexpected factory name.",
122             "1b",
123             cf.toString() );
124     }
125     
126     
127     public void testToString1a()
128     {
129         // try with a named inner class.
130
CxFactory cf = new MyCxFactory( "1a", true );
131         assertEquals(
132             "Returned unexpected factory name.",
133             TC+"-1a",
134             cf.toString() );
135     }
136     
137     
138     public void testToString2()
139     {
140         // try with an anonymous inner class.
141
// CxFactory should use the name of the owning class's name,
142
// not the inner class's name.
143
CxFactory cf = new MyCxFactory( "2" ) { };
144         assertEquals(
145             "Returned unexpected factory name.",
146             "2",
147             cf.toString() );
148     }
149     
150     
151     public void testToString2b()
152     {
153         // try with an anonymous inner class.
154
// CxFactory should use the name of the owning class's name,
155
// not the inner class's name.
156
CxFactory cf = new MyCxFactory( "2b", false ) { };
157         assertEquals(
158             "Returned unexpected factory name.",
159             "2b",
160             cf.toString() );
161     }
162     
163     
164     public void testToString2a()
165     {
166         // try with an anonymous inner class.
167
// CxFactory should use the name of the owning class's name,
168
// not the inner class's name.
169
CxFactory cf = new MyCxFactory( "2a", true ) { };
170         assertEquals(
171             "Returned unexpected factory name.",
172             TC+"-2a",
173             cf.toString() );
174     }
175     
176     
177     public void testToString3()
178     {
179         // try with a static inner class.
180
// CxFactory should use the name of the owning class's name,
181
// not the inner class's name.
182
CxFactory cf = new MyStaticCxFactory( "3" ) { };
183         assertEquals(
184             "Returned unexpected factory name.",
185             "3",
186             cf.toString() );
187     }
188     
189     
190     public void testToString3b()
191     {
192         // try with a static inner class.
193
// CxFactory should use the name of the owning class's name,
194
// not the inner class's name.
195
CxFactory cf = new MyStaticCxFactory( "3b", false ) { };
196         assertEquals(
197             "Returned unexpected factory name.",
198             "3b",
199             cf.toString() );
200     }
201     
202     
203     public void testToString3a()
204     {
205         // try with a static inner class.
206
// CxFactory should use the name of the owning class's name,
207
// not the inner class's name.
208
CxFactory cf = new MyStaticCxFactory( "3a", true ) { };
209         assertEquals(
210             "Returned unexpected factory name.",
211             TC+"-3a",
212             cf.toString() );
213     }
214     
215     
216     public void testToString4()
217     {
218         // try with an outside, stand-alone class.
219
LOG.debug( "Test4:" );
220         CxFactory cf = new CxFactorySample( "4" );
221         LOG.debug( "Returned Sample factory toString: ["+cf.toString()+"]" );
222         assertEquals(
223             "Returned unexpected factory name.",
224             "4",
225             cf.toString() );
226     }
227     
228     
229     public void testToString4b()
230     {
231         // try with an outside, stand-alone class.
232
LOG.debug( "Test4:" );
233         CxFactory cf = new CxFactorySample( "4b", false );
234         LOG.debug( "Returned Sample factory toString: ["+cf.toString()+"]" );
235         assertEquals(
236             "Returned unexpected factory name.",
237             "4b",
238             cf.toString() );
239     }
240     
241     
242     public void testToString4a()
243     {
244         // try with an outside, stand-alone class.
245
LOG.debug( "Test4:" );
246         CxFactory cf = new CxFactorySample( "4a", true );
247         LOG.debug( "Returned Sample factory toString: ["+cf.toString()+"]" );
248         assertEquals(
249             "Returned unexpected factory name.",
250             "CxFactorySample-4a",
251             cf.toString() );
252     }
253     
254     
255     //-------------------------------------------------------------------------
256
// Standard JUnit declarations
257

258     
259     public static InterfaceTestSuite suite()
260     {
261         InterfaceTestSuite suite = ImplFactoryUTestI.suite();
262         
263         // yes, this is an inner class inside an inner class!
264
// shudder - luckily, this is only for testing.
265
suite.addFactory( new ImplFactory() {
266             public Object JavaDoc createImplObject() {
267                 return new MyStaticCxFactory( "A-B" );
268             }
269             
270             public String JavaDoc toString() {
271                 return "CxFactory-A";
272             }
273         } );
274         suite.addTestSuite( THIS_CLASS );
275         
276         return suite;
277     }
278     
279     public static void main( String JavaDoc[] args )
280     {
281         String JavaDoc[] name = { THIS_CLASS.getName() };
282         
283         // junit.textui.TestRunner.main( name );
284
// junit.swingui.TestRunner.main( name );
285

286         junit.textui.TestRunner.main( name );
287     }
288     
289     
290     /**
291      *
292      * @exception Exception thrown under any exceptional condition.
293      */

294     protected void setUp() throws Exception JavaDoc
295     {
296         super.setUp();
297         
298         // set ourself up
299
}
300     
301     
302     /**
303      *
304      * @exception Exception thrown under any exceptional condition.
305      */

306     protected void tearDown() throws Exception JavaDoc
307     {
308         // tear ourself down
309

310         
311         super.tearDown();
312     }
313 }
314
315
Popular Tags