KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)Sample2IUTestI.java
3  *
4  * Original author is Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * This code sample has been submitted to the public domain, to show
9  * 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 /**
24  * Tests the Sample2 interface.
25  * <P>
26  * Formatted for 70-column publication.
27  *
28  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
29  * @since March 1, 2002
30  * @version $Date: 2002/07/28 22:43:58 $
31  */

32 public class Sample2IUTestI extends InterfaceTestCase {
33     private static final Class JavaDoc THIS_CLASS = Sample2IUTestI.class;
34     
35     public static interface Sample2Factory {
36         public Sample2 create( String JavaDoc[] s );
37         public Sample2 create( String JavaDoc s );
38     }
39     
40     public Sample2IUTestI( String JavaDoc name, ImplFactory f ) {
41         super( name, Sample2Factory.class, f );
42     }
43
44     protected Sample2Factory createSample2Factory() {
45         return (Sample2Factory)createImplObject();
46     }
47
48     
49     protected Sample2 createSample2( String JavaDoc[] s ) {
50         Sample2 s2 = createSample2Factory().create( s );
51         assertNotNull( "factory returned null.", s2 );
52         return s2;
53     }
54
55     protected Sample2 createSample2( String JavaDoc s ) {
56         Sample2 s2 = createSample2Factory().create( s );
57         assertNotNull( "factory returned null.", s2 );
58         return s2;
59     }
60
61     //---------------------------------------------------------------
62
// Tests
63

64     public void testConstructor1() throws Exception JavaDoc {
65         Class JavaDoc c = createSample2( "a" ).getClass();
66         java.lang.reflect.Constructor JavaDoc cntr = c.getConstructor(
67             new Class JavaDoc[] { String JavaDoc[].class } );
68         assertNotNull( "Does not contain valid constructor.", cntr );
69     }
70     
71     
72     public void testGetStrings1() throws Exception JavaDoc {
73         Sample2 s2 = createSample2( "a" );
74         String JavaDoc s[] = s2.getStrings();
75         assertNotNull( "Null string array.", s );
76         assertEquals( "Incorrect array length.", 1, s.length );
77         assertEquals( "Returned element incorrect.", "a", s[0] );
78     }
79     
80     
81     public void testGetStrings2() throws Exception JavaDoc {
82         Sample2 s2 = createSample2( new String JavaDoc[] { "a", "b" } );
83         String JavaDoc s[] = s2.getStrings();
84         assertNotNull( "Null string array.", s );
85         assertEquals( "Incorrect array length.", 2, s.length );
86         assertEquals( "Returned element incorrect.", "a", s[0] );
87         assertEquals( "Returned element incorrect.", "b", s[1] );
88     }
89     
90     public static InterfaceTestSuite suite() {
91         InterfaceTestSuite suite =
92             new InterfaceTestSuite( THIS_CLASS );
93         return suite;
94     }
95 }
96
97
Popular Tags