KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > utility > test > TestDirectoryWalker


1 package net.firstpartners.nounit.utility.test;
2
3 /**
4  * Title: NoUnit - Identify Classes that are not being unit Tested
5  *
6  * Copyright (C) 2001 Paul Browne , FirstPartners.net
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @author Paul Browne
24  * @version 0.7
25  */

26
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33 import net.firstpartners.nounit.test.TestData;
34 import net.firstpartners.nounit.utility.DirectoryWalker;
35
36 import org.apache.log4j.Logger;
37
38 /**
39  * Class to test the Directory Walker
40  */

41 public class TestDirectoryWalker extends TestCase{
42
43     //handle to logger
44
static Logger log = Logger.getLogger(TestDirectoryWalker.class);
45
46   /**
47   * Constructor Required by Junit
48   * @param name
49   */

50     public TestDirectoryWalker(String JavaDoc name) {
51     super(name);
52   }
53
54   /**
55    * Method to setup logging test
56    */

57   protected void setUp()
58   {
59       //Put in Setup Code Here
60

61   }
62
63   /**
64   * Enable Junit to run this Class individually
65   * @param args
66   */

67   public static void main(String JavaDoc[] args) {
68       junit.textui.TestRunner.run (suite());
69   }
70
71   /**
72    * Enable Junit to run this class
73    * @return TestDataCaptureDefaults.class
74    */

75   public static Test suite() {
76       return new TestSuite(TestDirectoryWalker.class);
77   }
78
79   public void testSeeFiles() throws Exception JavaDoc {
80    
81       HashSet JavaDoc myResults =
82           DirectoryWalker.getFiles( TestData.SAMPLE_CLASS_SOURCE,".class" );
83       Iterator JavaDoc myList = myResults.iterator();
84       StringBuffer JavaDoc addList = new StringBuffer JavaDoc();
85            
86       //Get everything into String
87
while (myList.hasNext()) {
88         addList.append(myList.next());
89         addList.append("\n");
90     
91       }
92       String JavaDoc searchString = addList.toString();
93       
94       //Now Check that it's picked up all the sample files
95
//assertTrue(searchString.indexOf("G:\\NoUnitFiles\\net\\firstpartners\\nounit\\utility\\Logging.class")>-1);
96
//assertTrue(searchString.indexOf("G:\\NoUnitFiles\\net\\firstpartners\\nounit\\utility\\DirectoryWalker.class")>-1);
97
//assertTrue(searchString.indexOf("G:\\NoUnitFiles\\net\\firstpartners\\nounit\\utility\\NoUnitException.class")>-1);
98

99     }
100     
101       public void testSeeDirs() throws Exception JavaDoc {
102    
103       HashSet JavaDoc myResults = DirectoryWalker.getDirs(TestData.SAMPLE_CLASS_SOURCE);
104       Iterator JavaDoc myList = myResults.iterator();
105       StringBuffer JavaDoc addList = new StringBuffer JavaDoc();
106            
107       //Get everything into String
108
while (myList.hasNext()) {
109         addList.append(myList.next());
110         addList.append("\n");
111     
112       }
113       String JavaDoc searchString = addList.toString();
114       
115       log.debug(searchString);
116       
117       //Now Check that it's picked up all the sample files
118
//assertTrue(searchString.indexOf("G:\\NoUnitFiles\\net\\firstpartners\\nounit\\utility\\test")>-1);
119

120     }
121
122
123 }
124
Popular Tags