1 19 20 package org.netbeans.modules.java.source.usages; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import junit.framework.*; 25 import java.io.File ; 26 import java.io.FileOutputStream ; 27 import java.io.OutputStream ; 28 import java.util.Iterator ; 29 import java.util.LinkedList ; 30 import java.util.List ; 31 import org.netbeans.junit.NbTestCase; 32 33 37 public class LazyFileListTest extends NbTestCase { 38 39 private static final String [] 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 root; 53 54 public LazyFileListTest(String testName) { 55 super(testName); 56 } 57 58 private void createNewFile(File f) throws Exception { 59 f.createNewFile(); 60 61 if (f.length() == 0) { 62 OutputStream out = new FileOutputStream (f); 64 65 try { 66 out.write('\n'); 67 } finally { 68 out.close(); 69 } 70 } 71 } 72 73 protected void setUp() throws Exception { 74 this.clearWorkDir(); 75 this.root = this.getWorkDir(); 76 File f = new File (new File (new File (root,"a"),"b"),"c"); 77 f.mkdirs(); 78 File t = new File (f,"c1.java"); 79 createNewFile(t); 80 t = new File (f,"c2.java"); 81 createNewFile(t); 82 t = new File (f,"c3.txt"); 83 createNewFile(t); 84 f = f.getParentFile(); 85 t = new File (f,"b1.java"); 86 createNewFile(t); 87 t = new File (f,"b2.java"); 88 createNewFile(t); 89 t = new File (f,"b3.java"); 90 t.createNewFile(); 91 t = new File (f,"b3.txt"); 92 createNewFile(t); 93 f = f.getParentFile(); 94 t = new File (f,"a1.java"); 95 createNewFile(t); 96 t = new File (f,"a2.java"); 97 createNewFile(t); 98 t = new File (f,"a3.txt"); 99 createNewFile(t); 100 101 f = new File (new File (root,"d"),"e"); 102 f.mkdirs(); 103 t = new File (f,"e1.java"); 104 createNewFile(t); 105 t = new File (f,"e2.java"); 106 createNewFile(t); 107 f = f.getParentFile(); 108 t = new File (f,"d1.java"); 109 createNewFile(t); 110 t = new File (f,"d2.java"); 111 createNewFile(t); 112 113 } 114 115 protected void tearDown() throws Exception { 116 } 117 118 public void testIterator() { 119 RepositoryUpdater.LazyFileList lfl = new RepositoryUpdater.LazyFileList (this.root); 120 List <String > fileNames = new ArrayList (); 121 for (File f :lfl) { 122 fileNames.add(f.getName()); 123 } 124 assertEquals(Arrays.asList(EXPECTED_NAMES),fileNames); 125 } 126 127 128 129 } 130 | Popular Tags |