KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > report > IReportGeneratorUTestI


1 /*
2  * @(#)IReportGeneratorUTestI.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.codecoverage.v2.report;
28
29 import java.io.File JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
33 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
34 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
35 import net.sourceforge.groboutils.codecoverage.v2.datastore.DirMetaDataReader;
36 import net.sourceforge.groboutils.codecoverage.v2.logger.DirectoryChannelLogReader;
37 import net.sourceforge.groboutils.junit.v1.iftc.ImplFactory;
38 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestCase;
39 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite;
40
41 import org.w3c.dom.Element JavaDoc;
42
43
44 /**
45  * Tests the IReportGenerator interface.
46  *
47  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
48  * @version $Date: 2004/04/15 05:48:29 $
49  * @since December 28, 2002
50  */

51 public class IReportGeneratorUTestI extends InterfaceTestCase
52 {
53     //-------------------------------------------------------------------------
54
// Standard JUnit Class-specific declarations
55

56     private static final Class JavaDoc THIS_CLASS = IReportGeneratorUTestI.class;
57     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
58     
59     public IReportGeneratorUTestI( String JavaDoc name, ImplFactory f )
60     {
61         super( name, IReportGenerator.class, f );
62     }
63
64     
65     public IReportGenerator createIReportGenerator()
66     {
67         return (IReportGenerator)createImplObject();
68     }
69
70
71     //-------------------------------------------------------------------------
72
// Tests
73

74     
75     public void testWriteReport1() throws Exception JavaDoc
76     {
77         IReportGenerator rg = createIReportGenerator();
78         
79         try
80         {
81             rg.createReport( null, null );
82             fail( "Did not throw IllegalArgumentException." );
83         }
84         catch (IllegalArgumentException JavaDoc e)
85         {
86             // test exception
87
}
88     }
89     
90     
91     public void testWriteReport2() throws Exception JavaDoc
92     {
93         IReportGenerator rg = createIReportGenerator();
94         
95         try
96         {
97             rg.createReport( createIAnalysisModule( "a", "b", "c"), null );
98             fail( "Did not throw IllegalArgumentException." );
99         }
100         catch (IllegalArgumentException JavaDoc e)
101         {
102             // test exception
103
}
104     }
105     
106     
107     public void testWriteReport3() throws Exception JavaDoc
108     {
109         IReportGenerator rg = createIReportGenerator();
110         
111         try
112         {
113             rg.createReport( null, createAnalysisModuleData() );
114             fail( "Did not throw IllegalArgumentException." );
115         }
116         catch (IllegalArgumentException JavaDoc e)
117         {
118             // test exception
119
}
120     }
121     
122     
123     public void testWriteReport4() throws Exception JavaDoc
124     {
125         IReportGenerator rg = createIReportGenerator();
126         
127         rg.createReport( createIAnalysisModule( "a", "b", "c"),
128             createAnalysisModuleData() );
129     }
130     
131     
132     public void testWriteReport8() throws Exception JavaDoc
133     {
134         IReportGenerator rg = createIReportGenerator();
135         Element JavaDoc el = rg.createReport( createIAnalysisModule( "a", "b", "c" ),
136             createAnalysisModuleData() );
137         DOC.getLog().info( "Retrieved report: ["+el+"]" );
138         assertNotNull(
139             "Didn't create an element.",
140             el );
141     }
142     
143     
144     
145     //public void writeReport( IAnalysisModule module, AnalysisModuleData data,
146
// Writer out )
147
// throws IOException;
148

149     
150     //-------------------------------------------------------------------------
151
// Helpers
152

153     protected IAnalysisModule createIAnalysisModule( String JavaDoc name, String JavaDoc unit,
154             String JavaDoc mime )
155     {
156         return CCCreatorUtil.createIAnalysisModule( name, unit, mime );
157     }
158     
159     
160     /**
161      * This is actually an extended test of DirMetaDataReader: even if the
162      * DirMetaDataReader instance goes out of scope and its generated
163      * DirClassMetaDataReader instances are still in scope, the DirMetaDataIO
164      * won't close on us.
165      */

166     protected AnalysisModuleData createAnalysisModuleData() throws IOException JavaDoc
167     {
168         IAnalysisModule am = createIAnalysisModule( "a", "b", "text/plain" );
169         CCCreatorUtil.SimpleClassLogData[] scld = new
170             CCCreatorUtil.SimpleClassLogData[] {
171                 new CCCreatorUtil.SimpleClassLogData( "a.MyClass-1138",
172                     new int[] { 1,2,1 }, new int[] { 11, 2, 13 } ),
173             };
174         File JavaDoc basedir = CCCreatorUtil.createNewDirectory();
175         return CCCreatorUtil.createAnalysisModuleData( am,
176             createDirMetaDataReader( basedir ),
177             createDirectoryChannelLogReader( basedir, scld ) );
178     }
179     
180     
181     protected DirMetaDataReader createDirMetaDataReader( File JavaDoc basedir )
182             throws IOException JavaDoc
183     {
184         return CCCreatorUtil.createDirMetaDataReader( basedir,
185             new Class JavaDoc[] { THIS_CLASS, String JavaDoc.class },
186             CCCreatorUtil.createAnalysisModules( 2 ) );
187     }
188     
189     
190     protected DirectoryChannelLogReader createDirectoryChannelLogReader(
191         File JavaDoc basedir, CCCreatorUtil.SimpleClassLogData[] data )
192     {
193         return CCCreatorUtil.createDirectoryChannelLogReader( basedir, data,
194             (short)100 );
195     }
196     
197     
198     //-------------------------------------------------------------------------
199
// Standard JUnit declarations
200

201     
202     public static InterfaceTestSuite suite()
203     {
204         InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS );
205         
206         return suite;
207     }
208     
209     public static void main( String JavaDoc[] args )
210     {
211         String JavaDoc[] name = { THIS_CLASS.getName() };
212         
213         // junit.textui.TestRunner.main( name );
214
// junit.swingui.TestRunner.main( name );
215

216         junit.textui.TestRunner.main( name );
217     }
218     
219     
220     /**
221      *
222      * @exception Exception thrown under any exceptional condition.
223      */

224     protected void setUp() throws Exception JavaDoc
225     {
226         super.setUp();
227         
228         // set ourself up
229
}
230     
231     
232     /**
233      *
234      * @exception Exception thrown under any exceptional condition.
235      */

236     protected void tearDown() throws Exception JavaDoc
237     {
238         // tear ourself down
239

240         
241         super.tearDown();
242     }
243 }
244
245
Popular Tags