001: /*
002: * @(#)InterfaceTestSuiteUTest.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.junit.v1.iftc;
028:
029: //import net.sourceforge.groboutils.testing.junitlog.v1.*;
030: import org.easymock.EasyMock;
031: import org.easymock.MockControl;
032: import junit.framework.Test;
033: import junit.framework.TestCase;
034: import junit.framework.TestSuite;
035: import java.util.Enumeration;
036:
037: /**
038: * Tests the InterfaceTestSuite class.
039: *
040: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
041: * @since March 1, 2002
042: * @version $Date: 2003/02/10 22:52:23 $
043: */
044: public class InterfaceTestSuiteUTest extends TestCase {
045: //-------------------------------------------------------------------------
046: // Standard JUnit Class-specific declarations
047:
048: private static final Class THIS_CLASS = InterfaceTestSuiteUTest.class;
049:
050: // private static final IJUnitDocumentor LOG = (new JUnitLog(THIS_CLASS)).getDocumentor();
051:
052: public InterfaceTestSuiteUTest(String name) {
053: super (name);
054: }
055:
056: //-------------------------------------------------------------------------
057: // Tests
058:
059: public void testConstructor1() {
060: new InterfaceTestSuite();
061: }
062:
063: public void testConstructor2() {
064: try {
065: new InterfaceTestSuite((Class) null);
066: fail("Did not throw IllegalArgumentException.");
067: } catch (IllegalArgumentException iae) {
068: // test exception?
069: }
070: }
071:
072: public void testConstructor3() {
073: new InterfaceTestSuite(this .getClass());
074: }
075:
076: public void testConstructor4() {
077: try {
078: new InterfaceTestSuite((Class) null, (ImplFactory) null);
079: fail("Did not throw IllegalArgumentException.");
080: } catch (IllegalArgumentException iae) {
081: // test exception?
082: }
083: }
084:
085: public class ObjectFactory implements ImplFactory {
086: public Object createImplObject() {
087: return new Object();
088: }
089: }
090:
091: public class NullFactory implements ImplFactory {
092: public Object createImplObject() {
093: return null;
094: }
095: }
096:
097: public class IAEFactory implements ImplFactory {
098: public Object createImplObject() {
099: return new IllegalArgumentException();
100: }
101: }
102:
103: public void testConstructor5() {
104: try {
105: new InterfaceTestSuite((Class) null, new ObjectFactory());
106: fail("Did not throw IllegalArgumentException.");
107: } catch (IllegalArgumentException iae) {
108: // test exception?
109: }
110: }
111:
112: public void testConstructor6() {
113: try {
114: new InterfaceTestSuite(this .getClass(), null);
115: fail("Did not throw IllegalArgumentException.");
116: } catch (IllegalArgumentException iae) {
117: // test exception?
118: }
119: }
120:
121: public void testConstructor7() {
122: new InterfaceTestSuite(this .getClass(), new ObjectFactory());
123: }
124:
125: public void testAddFactory1() {
126: InterfaceTestSuite its = new InterfaceTestSuite();
127: try {
128: its.addFactory(null);
129: fail("Did not throw IllegalArgumentException.");
130: } catch (IllegalArgumentException iae) {
131: // test exception?
132: }
133: }
134:
135: public void testAddFactory2() {
136: InterfaceTestSuite its = new InterfaceTestSuite();
137: its.addFactory(new ObjectFactory());
138: assertEquals("Not right number of factories.", 1, its.creators
139: .size());
140: }
141:
142: public void testAddFactories1() {
143: InterfaceTestSuite its = new InterfaceTestSuite();
144: try {
145: its.addFactories(null);
146: fail("Did not throw IllegalArgumentException.");
147: } catch (IllegalArgumentException iae) {
148: // test exception?
149: }
150: }
151:
152: public void testAddFactories2() {
153: InterfaceTestSuite its = new InterfaceTestSuite();
154: try {
155: its.addFactories(new ImplFactory[1]);
156: fail("Did not throw IllegalArgumentException.");
157: } catch (IllegalArgumentException iae) {
158: // test exception?
159: }
160: }
161:
162: public void testAddFactories3() {
163: InterfaceTestSuite its = new InterfaceTestSuite();
164: its.addFactories(new ImplFactory[0]);
165: assertEquals("Not right number of factories.", 0, its.creators
166: .size());
167: }
168:
169: public void testAddFactories4() {
170: InterfaceTestSuite its = new InterfaceTestSuite();
171: its.addFactories(new ImplFactory[] { new ObjectFactory(),
172: new ObjectFactory() });
173: assertEquals("Not right number of factories.", 2, its.creators
174: .size());
175: }
176:
177: public void testAddTests1() {
178: InterfaceTestSuite its = new InterfaceTestSuite();
179: try {
180: its.addTests(null);
181: fail("Did not throw IllegalArgumentException.");
182: } catch (IllegalArgumentException iae) {
183: // test exception?
184: }
185: }
186:
187: public void testAddTests2() {
188: InterfaceTestSuite its = new InterfaceTestSuite();
189: its.addTests(new Test[0]);
190: }
191:
192: public void testAddTests3() {
193: InterfaceTestSuite its = new InterfaceTestSuite();
194: its.addTests(new Test[1]);
195: }
196:
197: public void testAddTests4() {
198: InterfaceTestSuite its = new InterfaceTestSuite();
199: its.addTests(new Test[] { new TestCase("") {
200: }, new TestCase("") {
201: } });
202: }
203:
204: public void testAddTestSuite1() {
205: InterfaceTestSuite its = new InterfaceTestSuite();
206: its.addTestSuite(getClass());
207: }
208:
209: public void testTestAt1() {
210: InterfaceTestSuite its = new InterfaceTestSuite();
211: its.addTestSuite(getClass());
212: its.testAt(0);
213: }
214:
215: public void testTestCount1() {
216: InterfaceTestSuite its = new InterfaceTestSuite();
217: its.testCount();
218: }
219:
220: public void testTests1() {
221: InterfaceTestSuite its = new InterfaceTestSuite();
222: its.tests();
223: }
224:
225: public static interface Intfc1 {
226: }
227:
228: public static interface Intfc2 extends Intfc1 {
229: }
230:
231: public static class Infc1TestCase extends InterfaceTestCase {
232: public Infc1TestCase(String name, ImplFactory f) {
233: super (name, Intfc1.class, f);
234: }
235:
236: public void test1() {
237: }
238:
239: public static InterfaceTestSuite suite() {
240: InterfaceTestSuite suite = new InterfaceTestSuite(
241: Infc1TestCase.class);
242: return suite;
243: }
244: }
245:
246: public static class Infc2TestCase extends InterfaceTestCase {
247: public Infc2TestCase(String name, ImplFactory f) {
248: super (name, Intfc1.class, f);
249: }
250:
251: public void test2() {
252: }
253:
254: public static InterfaceTestSuite suite() {
255: InterfaceTestSuite suite = new InterfaceTestSuite(
256: Infc2TestCase.class);
257: suite.addInterfaceTestSuite(Infc1TestCase.suite());
258: return suite;
259: }
260: }
261:
262: public void testAddInnerITS()
263: {
264: InterfaceTestSuite its = Infc2TestCase.suite();
265:
266: Enumeration enum = its.tests();
267: assertNotNull(
268: "Must not return null",
269: enum );
270: assertTrue(
271: "Must have at least 1 test.",
272: enum.hasMoreElements() );
273: assertNotNull(
274: "Must have non-null first test.",
275: enum.nextElement() );
276: assertTrue(
277: "Must have 2 tests.",
278: enum.hasMoreElements() );
279: assertNotNull(
280: "Must have non-null second test.",
281: enum.nextElement() );
282: assertTrue(
283: "Must have exactly 2 tests.",
284: !enum.hasMoreElements() );
285: }
286:
287: public static class JUnit3_8TestCase extends TestCase {
288: public void test1() {
289: }
290: }
291:
292: public void testJUnit3_8Compat()
293: {
294: InterfaceTestSuite its = new InterfaceTestSuite(
295: JUnit3_8TestCase.class );
296:
297: Enumeration enum = its.tests();
298: assertNotNull(
299: "Must not return null",
300: enum );
301: assertTrue(
302: "Must have at least 1 test.",
303: enum.hasMoreElements() );
304: assertNotNull(
305: "Must have non-null first test.",
306: enum.nextElement() );
307: assertTrue(
308: "Must have exactly 1 test.",
309: !enum.hasMoreElements() );
310: }
311:
312: //-------------------------------------------------------------------------
313: // Standard JUnit declarations
314:
315: public static Test suite() {
316: TestSuite suite = new TestSuite(THIS_CLASS);
317:
318: return suite;
319: }
320:
321: public static void main(String[] args) {
322: String[] name = { THIS_CLASS.getName() };
323:
324: // junit.textui.TestRunner.main( name );
325: // junit.swingui.TestRunner.main( name );
326:
327: junit.textui.TestRunner.main(name);
328: }
329:
330: /**
331: *
332: * @exception Exception thrown under any exceptional condition.
333: */
334: protected void setUp() throws Exception {
335: super .setUp();
336:
337: // set ourself up
338: }
339:
340: /**
341: *
342: * @exception Exception thrown under any exceptional condition.
343: */
344: protected void tearDown() throws Exception {
345: // tear ourself down
346:
347: super.tearDown();
348: }
349: }
|