01: /*
02: * @(#)Sample2IUTestI.java
03: *
04: * Original author is Matt Albrecht
05: * groboclown@users.sourceforge.net
06: * http://groboutils.sourceforge.net
07: *
08: * This code sample has been submitted to the public domain, to show
09: * uses for the Interface testing framework.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14: */
15:
16: package net.sourceforge.groboutils.junit.v1.iftc;
17:
18: import junit.framework.Test;
19: import junit.framework.TestCase;
20: import junit.framework.TestSuite;
21:
22: /**
23: * Tests the Sample2 interface.
24: * <P>
25: * Formatted for 70-column publication.
26: *
27: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
28: * @since March 1, 2002
29: * @version $Date: 2002/07/28 22:43:58 $
30: */
31: public class Sample2IUTestI extends InterfaceTestCase {
32: private static final Class THIS_CLASS = Sample2IUTestI.class;
33:
34: public static interface Sample2Factory {
35: public Sample2 create(String[] s);
36:
37: public Sample2 create(String s);
38: }
39:
40: public Sample2IUTestI(String name, ImplFactory f) {
41: super (name, Sample2Factory.class, f);
42: }
43:
44: protected Sample2Factory createSample2Factory() {
45: return (Sample2Factory) createImplObject();
46: }
47:
48: protected Sample2 createSample2(String[] s) {
49: Sample2 s2 = createSample2Factory().create(s);
50: assertNotNull("factory returned null.", s2);
51: return s2;
52: }
53:
54: protected Sample2 createSample2(String s) {
55: Sample2 s2 = createSample2Factory().create(s);
56: assertNotNull("factory returned null.", s2);
57: return s2;
58: }
59:
60: //---------------------------------------------------------------
61: // Tests
62:
63: public void testConstructor1() throws Exception {
64: Class c = createSample2("a").getClass();
65: java.lang.reflect.Constructor cntr = c
66: .getConstructor(new Class[] { String[].class });
67: assertNotNull("Does not contain valid constructor.", cntr);
68: }
69:
70: public void testGetStrings1() throws Exception {
71: Sample2 s2 = createSample2("a");
72: String s[] = s2.getStrings();
73: assertNotNull("Null string array.", s);
74: assertEquals("Incorrect array length.", 1, s.length);
75: assertEquals("Returned element incorrect.", "a", s[0]);
76: }
77:
78: public void testGetStrings2() throws Exception {
79: Sample2 s2 = createSample2(new String[] { "a", "b" });
80: String s[] = s2.getStrings();
81: assertNotNull("Null string array.", s);
82: assertEquals("Incorrect array length.", 2, s.length);
83: assertEquals("Returned element incorrect.", "a", s[0]);
84: assertEquals("Returned element incorrect.", "b", s[1]);
85: }
86:
87: public static InterfaceTestSuite suite() {
88: InterfaceTestSuite suite = new InterfaceTestSuite(THIS_CLASS);
89: return suite;
90: }
91: }
|