KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > classreader > TestDirectoryExplorer


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.classreader;
34
35 import java.io.*;
36 import java.util.*;
37
38 import junit.framework.*;
39
40 public class TestDirectoryExplorer extends TestCase {
41     public static final String JavaDoc TEST_FILENAME = "classes" + File.separator + "test.class";
42     public static final String JavaDoc OTHER_FILENAME = "tests" + File.separator + "JarJarDiff" + File.separator + "build.xml";
43     public static final String JavaDoc MISSING_FILENAME = "tests" + File.separator + "JarJarDiff" + File.separator + "missing";
44     public static final String JavaDoc TEST_DIRNAME = "tests" + File.separator + "JarJarDiff" + File.separator + "old";
45     public static final String JavaDoc OTHER_DIRNAME = "tests" + File.separator + "JarJarDiff" + File.separator + "new";
46     
47     public void testExploreFilename() throws IOException {
48         DirectoryExplorer explorer = new DirectoryExplorer(TEST_FILENAME);
49
50         List list = new ArrayList(explorer.getCollection());
51         
52         assertEquals("size", 1, list.size());
53         assertEquals(TEST_FILENAME, ((File) list.get(0)).getPath());
54     }
55
56     public void testExploreOtherFilename() throws IOException {
57         DirectoryExplorer explorer = new DirectoryExplorer(OTHER_FILENAME);
58
59         List list = new ArrayList(explorer.getCollection());
60         
61         assertEquals("size", 1, list.size());
62         assertEquals(OTHER_FILENAME, ((File) list.get(0)).getPath());
63     }
64
65     public void testExploreMissingFilename() throws IOException {
66         DirectoryExplorer explorer = new DirectoryExplorer(MISSING_FILENAME);
67         
68         assertEquals("size", 0, explorer.getCollection().size());
69     }
70
71     public void testExploreDirectory() throws IOException {
72         DirectoryExplorer explorer = new DirectoryExplorer(TEST_DIRNAME);
73
74         List list = new ArrayList(explorer.getCollection());
75         
76         assertEquals("size", 59, list.size());
77         assertEquals(TEST_DIRNAME, ((File) list.get(0)).getPath());
78     }
79     
80     public void testExploreMultipleDirectories() throws IOException {
81         Collection directories = new ArrayList();
82         directories.add(TEST_DIRNAME);
83         directories.add(OTHER_DIRNAME);
84         
85         DirectoryExplorer explorer = new DirectoryExplorer(directories);
86
87         List list = new ArrayList(explorer.getCollection());
88         
89         assertEquals("size", 118, list.size());
90         assertEquals(TEST_DIRNAME, ((File) list.get(0)).getPath());
91     }
92     
93     public void testExploreSingletonFile() throws IOException {
94         Collection files = new ArrayList();
95         files.add(TEST_FILENAME);
96         
97         DirectoryExplorer explorer = new DirectoryExplorer(files);
98
99         List list = new ArrayList(explorer.getCollection());
100         
101         assertEquals("size", 1, list.size());
102         assertEquals(TEST_FILENAME, ((File) list.get(0)).getPath());
103     }
104 }
105
Popular Tags