KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > logger > DirectoryChannelLogReaderUTest


1 /*
2  * @(#)DirectoryChannelLogReaderUTest.java
3  *
4  * Copyright (C) 2003-2004 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.logger;
28
29 import java.io.File JavaDoc;
30 import java.io.FileWriter JavaDoc;
31 import java.io.IOException JavaDoc;
32
33 import junit.framework.Test;
34 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
35 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
36 import net.sourceforge.groboutils.codecoverage.v2.IChannelLogReaderUTestI;
37 import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReader;
38 import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReaderUTestI;
39 import net.sourceforge.groboutils.junit.v1.SubTestTestCase;
40 import net.sourceforge.groboutils.junit.v1.iftc.CxFactory;
41 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite;
42
43
44 /**
45  * Tests the DirectoryChannelLogReader class.
46  *
47  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
48  * @version $Date: 2004/07/07 09:39:13 $
49  * @since January 22, 2003
50  */

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

56     private static final Class JavaDoc THIS_CLASS = DirectoryChannelLogReaderUTest.class;
57     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
58     
59     public DirectoryChannelLogReaderUTest( String JavaDoc name )
60     {
61         super( name );
62     }
63
64
65     //-------------------------------------------------------------------------
66
// Tests
67

68     
69     public void testConstructor1() throws Exception JavaDoc
70     {
71         Thread.sleep( 100 );
72         File JavaDoc base = new File JavaDoc( ".",
73             Long.toString( System.currentTimeMillis() ) );
74         try
75         {
76             new DirectoryChannelLogReader( base, (short)0 );
77             fail( "Didn't throw IllegalArgumentException." );
78         }
79         catch (IllegalArgumentException JavaDoc ex)
80         {
81             // test exception
82
}
83     }
84     
85     
86     public void testConstructor2() throws Exception JavaDoc
87     {
88         Thread.sleep( 100 );
89         File JavaDoc base = CCCreatorUtil.createNewDirectory();
90         try
91         {
92             new DirectoryChannelLogReader( base, (short)0 );
93             fail( "Didn't throw IllegalArgumentException." );
94         }
95         catch (IllegalArgumentException JavaDoc ex)
96         {
97             // test exception
98
}
99     }
100     
101     
102     public void testGetReaderForClassSignature1() throws IOException JavaDoc
103     {
104         String JavaDoc classSig = "a.MyClass-1";
105         File JavaDoc outdir = CCCreatorUtil.createNewDirectory();
106         File JavaDoc fd1 = new File JavaDoc( outdir, "0" );
107         fd1.mkdirs();
108         File JavaDoc cd1 = new File JavaDoc( fd1, classSig +
109             DirectoryChannelLogger.CLASS_LOG_EXTENTION );
110         FileWriter JavaDoc fw = new FileWriter JavaDoc( cd1 );
111         fw.write( "0001 0002\n" );
112         fw.close();
113         DirectoryChannelLogReader dclr = new DirectoryChannelLogReader(
114             outdir, (short)0 );
115         final IClassChannelLogReader cclr = dclr.
116             getReaderForClassSignature( classSig );
117         assertNotNull(
118             "Returned null class channel log reader.",
119             cclr );
120         assertTrue(
121             "Not correct type (was "+cclr.getClass().getName()+").",
122             cclr instanceof DirectoryClassChannelLogReader );
123         
124         InterfaceTestSuite suite = IClassChannelLogReaderUTestI.suite();
125         suite.addFactory( new CxFactory( "GetReader1" ) {
126             public Object JavaDoc createImplObject() throws IOException JavaDoc {
127                 return cclr;
128             }
129         } );
130         addSubTest( suite );
131     }
132     
133     
134     public void testGetReaderForClassSignature2() throws IOException JavaDoc
135     {
136         String JavaDoc classSig = "a.MyClass-1";
137         File JavaDoc outdir = CCCreatorUtil.createNewDirectory();
138         File JavaDoc fd1 = new File JavaDoc( outdir, "0" );
139         fd1.mkdirs();
140         DirectoryChannelLogReader dclr = new DirectoryChannelLogReader(
141             outdir, (short)0 );
142         final IClassChannelLogReader cclr = dclr.
143             getReaderForClassSignature( classSig );
144         assertNotNull(
145             "Returned null class channel log reader.",
146             cclr );
147         assertTrue(
148             "Not correct type (was "+cclr.getClass().getName()+").",
149             cclr instanceof EmptyClassChannelLogReader );
150         
151         InterfaceTestSuite suite = IClassChannelLogReaderUTestI.suite();
152         suite.addFactory( new CxFactory( "GetReader2" ) {
153             public Object JavaDoc createImplObject() throws IOException JavaDoc {
154                 return cclr;
155             }
156         } );
157         addSubTest( suite );
158     }
159     
160     
161     //-------------------------------------------------------------------------
162
// Helpers
163

164     
165     
166     //-------------------------------------------------------------------------
167
// Standard JUnit declarations
168

169     
170     public static Test suite()
171     {
172         InterfaceTestSuite suite = IChannelLogReaderUTestI.suite();
173         suite.addTestSuite( THIS_CLASS );
174         suite.addFactory( new CxFactory( "A" ) {
175             public Object JavaDoc createImplObject() throws IOException JavaDoc {
176                 File JavaDoc base = CCCreatorUtil.createNewDirectory();
177                 File JavaDoc zero = new File JavaDoc( base, "0" );
178                 zero.mkdirs();
179                 return new DirectoryChannelLogReader( base, (short)0 );
180             }
181         } );
182         
183         return suite;
184     }
185     
186     public static void main( String JavaDoc[] args )
187     {
188         String JavaDoc[] name = { THIS_CLASS.getName() };
189         
190         // junit.textui.TestRunner.main( name );
191
// junit.swingui.TestRunner.main( name );
192

193         junit.textui.TestRunner.main( name );
194     }
195     
196     
197     /**
198      *
199      * @exception Exception thrown under any exceptional condition.
200      */

201     protected void setUp() throws Exception JavaDoc
202     {
203         super.setUp();
204
205        
206         // set ourself up
207
}
208     
209     
210     /**
211      *
212      * @exception Exception thrown under any exceptional condition.
213      */

214     protected void tearDown() throws Exception JavaDoc
215     {
216         // tear ourself down
217

218         
219         super.tearDown();
220     }
221 }
222
223
Popular Tags