KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)DirectoryChannelLoggerUTest.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
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
35 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
36
37
38 /**
39  * Tests the DirectoryChannelLogger class.
40  *
41  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
42  * @version $Date: 2004/07/07 09:39:13 $
43  * @since January 22, 2003
44  */

45 public class DirectoryChannelLoggerUTest extends TestCase
46 {
47     //-------------------------------------------------------------------------
48
// Standard JUnit Class-specific declarations
49

50     private static final Class JavaDoc THIS_CLASS = DirectoryChannelLoggerUTest.class;
51     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
52     
53     public DirectoryChannelLoggerUTest( String JavaDoc name )
54     {
55         super( name );
56     }
57
58
59     //-------------------------------------------------------------------------
60
// Tests
61

62     
63     public void testConstructor1()
64     {
65         new DirectoryChannelLogger( null );
66     }
67     
68     
69     public void testNullDir1()
70     {
71         DirectoryChannelLogger dcl = new DirectoryChannelLogger( null );
72         short a = (short)1;
73         dcl.cover( "a", a, a );
74         dcl.cover( "b", a, a );
75         dcl.cover( "c", a, a );
76     }
77     
78     
79     public void testCreateFile1()
80     {
81         // test the base directory + one up not existing
82
File JavaDoc basedir = CCCreatorUtil.createNewDirectory();
83         File JavaDoc otherDir = new File JavaDoc( basedir, "1" );
84         otherDir = new File JavaDoc( otherDir, "2" );
85         DirectoryChannelLogger dcl = new DirectoryChannelLogger( otherDir );
86         dcl.cover( "a", (short)1, (short)1 );
87         File JavaDoc outputFile = new File JavaDoc( otherDir, "a.class.log" );
88         assertTrue(
89             "Incorrectly was able to create output file.",
90             !outputFile.exists() );
91     }
92     
93     
94     public void testCreateFile2()
95     {
96         // test the base directory already existing
97
File JavaDoc basedir = CCCreatorUtil.createNewDirectory();
98         DirectoryChannelLogger dcl = new DirectoryChannelLogger( basedir );
99         dcl.cover( "a", (short)1, (short)1 );
100         File JavaDoc outputFile = new File JavaDoc( basedir, "a.class.log" );
101         assertTrue(
102             "Did not create output file.",
103             outputFile.exists() );
104     }
105     
106     
107     public void testCreateFile3()
108     {
109         // test the base directory not existing, but the one up does
110
File JavaDoc basedir = CCCreatorUtil.createNewDirectory();
111         File JavaDoc otherDir = new File JavaDoc( basedir, "1" );
112         DirectoryChannelLogger dcl = new DirectoryChannelLogger( otherDir );
113         dcl.cover( "a", (short)1, (short)1 );
114         File JavaDoc outputFile = new File JavaDoc( otherDir, "a.class.log" );
115         assertTrue(
116             "Did not create output file.",
117             outputFile.exists() );
118     }
119     
120     
121     public void testCreateCoverString1()
122     {
123         assertEquals(
124             "Didn't convert right",
125             "0001 0004\n",
126             coverString( 0x1, 0x4 ) );
127     }
128     
129     
130     public void testCreateCoverString2()
131     {
132         assertEquals(
133             "Didn't convert right",
134             "0030 FFDD\n",
135             coverString( 0x30, 0xFFDD ) );
136     }
137     
138     
139     public void testCreateCoverString3()
140     {
141         assertEquals(
142             "Didn't convert right",
143             "0000 0000\n",
144             coverString( 0x0, 0x0 ) );
145     }
146     
147     
148     //-------------------------------------------------------------------------
149
// Helpers
150

151     
152     protected String JavaDoc coverString( int a, int b )
153     {
154         char c[] = DirectoryChannelLogger.createCoverString(
155             (short)a, (short)b );
156         return new String JavaDoc( c );
157     }
158     
159     
160     
161     //-------------------------------------------------------------------------
162
// Standard JUnit declarations
163

164     
165     public static Test suite()
166     {
167         TestSuite suite = new TestSuite( THIS_CLASS );
168         
169         return suite;
170     }
171     
172     public static void main( String JavaDoc[] args )
173     {
174         String JavaDoc[] name = { THIS_CLASS.getName() };
175         
176         // junit.textui.TestRunner.main( name );
177
// junit.swingui.TestRunner.main( name );
178

179         junit.textui.TestRunner.main( name );
180     }
181     
182     
183     /**
184      *
185      * @exception Exception thrown under any exceptional condition.
186      */

187     protected void setUp() throws Exception JavaDoc
188     {
189         super.setUp();
190
191        
192         // set ourself up
193
}
194     
195     
196     /**
197      *
198      * @exception Exception thrown under any exceptional condition.
199      */

200     protected void tearDown() throws Exception JavaDoc
201     {
202         // tear ourself down
203

204         
205         super.tearDown();
206     }
207 }
208
209
Popular Tags