KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > usages > LazyFileListTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.source.usages;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import junit.framework.*;
25 import java.io.File JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.LinkedList JavaDoc;
30 import java.util.List JavaDoc;
31 import org.netbeans.junit.NbTestCase;
32
33 /**
34  *
35  * @author Tomas Zezula
36  */

37 public class LazyFileListTest extends NbTestCase {
38
39     private static final String JavaDoc[] EXPECTED_NAMES = {
40         "a1.java",
41         "a2.java",
42         "d1.java",
43         "d2.java",
44         "b1.java",
45         "b2.java",
46         "e1.java",
47         "e2.java",
48         "c1.java",
49         "c2.java"
50     };
51     
52     private File JavaDoc root;
53     
54     public LazyFileListTest(String JavaDoc testName) {
55         super(testName);
56     }
57     
58     private void createNewFile(File JavaDoc f) throws Exception JavaDoc {
59         f.createNewFile();
60         
61         if (f.length() == 0) {
62             //the RepositoryUpdater.LazyFileList needs some content:
63
OutputStream JavaDoc out = new FileOutputStream JavaDoc(f);
64             
65             try {
66                 out.write('\n');
67             } finally {
68                 out.close();
69             }
70         }
71     }
72
73     protected void setUp() throws Exception JavaDoc {
74         this.clearWorkDir();
75         this.root = this.getWorkDir();
76         File JavaDoc f = new File JavaDoc (new File JavaDoc(new File JavaDoc (root,"a"),"b"),"c");
77         f.mkdirs();
78         File JavaDoc t = new File JavaDoc (f,"c1.java");
79         createNewFile(t);
80         t = new File JavaDoc (f,"c2.java");
81         createNewFile(t);
82         t = new File JavaDoc (f,"c3.txt");
83         createNewFile(t);
84         f = f.getParentFile();
85         t = new File JavaDoc (f,"b1.java");
86         createNewFile(t);
87         t = new File JavaDoc (f,"b2.java");
88         createNewFile(t);
89         t = new File JavaDoc (f,"b3.java");
90         t.createNewFile();
91         t = new File JavaDoc (f,"b3.txt");
92         createNewFile(t);
93         f = f.getParentFile();
94         t = new File JavaDoc (f,"a1.java");
95         createNewFile(t);
96         t = new File JavaDoc (f,"a2.java");
97         createNewFile(t);
98         t = new File JavaDoc (f,"a3.txt");
99         createNewFile(t);
100         
101         f = new File JavaDoc(new File JavaDoc (root,"d"),"e");
102         f.mkdirs();
103         t = new File JavaDoc (f,"e1.java");
104         createNewFile(t);
105         t = new File JavaDoc (f,"e2.java");
106         createNewFile(t);
107         f = f.getParentFile();
108         t = new File JavaDoc (f,"d1.java");
109         createNewFile(t);
110         t = new File JavaDoc (f,"d2.java");
111         createNewFile(t);
112         
113     }
114
115     protected void tearDown() throws Exception JavaDoc {
116     }
117
118     public void testIterator() {
119         RepositoryUpdater.LazyFileList lfl = new RepositoryUpdater.LazyFileList (this.root);
120         List JavaDoc<String JavaDoc> fileNames = new ArrayList JavaDoc();
121         for (File JavaDoc f :lfl) {
122             fileNames.add(f.getName());
123         }
124         assertEquals(Arrays.asList(EXPECTED_NAMES),fileNames);
125     }
126     
127     
128     
129 }
130
Popular Tags