Lines 20-39
Link Here
|
20 |
package org.openide.filesystems; |
20 |
package org.openide.filesystems; |
21 |
|
21 |
|
22 |
import java.io.File; |
22 |
import java.io.File; |
|
|
23 |
import java.io.IOException; |
23 |
import java.net.URL; |
24 |
import java.net.URL; |
24 |
import org.netbeans.junit.MockServices; |
25 |
import org.netbeans.junit.MockServices; |
25 |
import org.netbeans.junit.NbTestCase; |
26 |
import org.netbeans.junit.NbTestCase; |
26 |
import org.openide.util.Utilities; |
27 |
import org.openide.util.Utilities; |
|
|
28 |
import org.netbeans.junit.MockServices; |
27 |
|
29 |
|
28 |
/** |
30 |
/** |
29 |
* @author Jesse Glick |
31 |
* @author Jesse Glick, Tim Boudreau |
30 |
*/ |
32 |
*/ |
31 |
public class FileUtilTest extends NbTestCase { |
33 |
public class FileUtilTest extends NbTestCase { |
32 |
|
34 |
|
33 |
public FileUtilTest(String n) { |
35 |
public FileUtilTest(String n) { |
34 |
super(n); |
36 |
super(n); |
35 |
} |
37 |
} |
36 |
|
38 |
|
|
|
39 |
protected void setUp() throws java.lang.Exception { |
40 |
MockServices.setServices(MyRepo.class); |
41 |
} |
42 |
|
37 |
public void testToFileObjectSlash() throws Exception { // #98388 |
43 |
public void testToFileObjectSlash() throws Exception { // #98388 |
38 |
if (!Utilities.isUnix()) { |
44 |
if (!Utilities.isUnix()) { |
39 |
return; |
45 |
return; |
Lines 60-64
Link Here
|
60 |
} |
66 |
} |
61 |
} |
67 |
} |
62 |
} |
68 |
} |
|
|
69 |
|
70 |
protected String[] getResources(String testName) { |
71 |
return new String[] { "somefolder/somefile.txt" }; |
72 |
} |
63 |
|
73 |
|
|
|
74 |
public void testGetConfigurationData() throws Exception { |
75 |
System.out.println("testGetConfigurationData"); |
76 |
FileObject f = FileUtil.getConfigurationFolder("folder", true); |
77 |
assertNotNull (f); |
78 |
FileObject f1 = FileUtil.getConfigurationFile ("folder/file.txt", true); |
79 |
assertNotNull (f1); |
80 |
assertEquals (f1, f.getFileObject ("file.txt")); |
81 |
} |
82 |
|
83 |
public void testCreateConfigurationFile() throws Exception { |
84 |
System.out.println("testCreateConfigurationFile"); |
85 |
FileObject f = FileUtil.getConfigurationFile("somewhere/file2.txt", true); |
86 |
assertNotNull (f); |
87 |
Exception ioe = null; |
88 |
FileObject f1 = null; |
89 |
try { |
90 |
f1 = FileUtil.getConfigurationFile ("somewhere/file2.txt", true); |
91 |
} catch (Exception e) { |
92 |
ioe = e; |
93 |
} |
94 |
assertNull (ioe); |
95 |
assertNotNull (f1); |
96 |
assertEquals (f, f1); |
97 |
ioe = null; |
98 |
try { |
99 |
f = FileUtil.getConfigurationFolder ("somewhere", true); |
100 |
} catch (Exception e) { |
101 |
ioe = e; |
102 |
} |
103 |
assertNull (ioe); |
104 |
assertEquals (f, f1.getParent()); |
105 |
|
106 |
f = FileUtil.getConfigurationFolder("folder", true); |
107 |
FileObject nue = f.createData ("hello.txt"); |
108 |
assertEquals (nue, FileUtil.getConfigurationFile("folder/hello.txt", true)); |
109 |
assertNotNull (f.getFileObject ("hello.txt")); |
110 |
assertTrue (f.getFileObject ("hello.txt").isData()); |
111 |
assertFalse (f.getFileObject ("hello.txt").isFolder()); |
112 |
} |
113 |
|
114 |
public void testCreateConfigurationFolder() throws Exception { |
115 |
System.out.println("testCreateConfigurationFolder"); |
116 |
FileObject f = FileUtil.getConfigurationFolder ("other", true); |
117 |
assertNotNull (f); |
118 |
Exception ioe = null; |
119 |
FileObject f1 = null; |
120 |
try { |
121 |
f1 = FileUtil.getConfigurationFolder("other", true); |
122 |
} catch (Exception e) { |
123 |
ioe = e; |
124 |
} |
125 |
assertNull (ioe); |
126 |
assertEquals (f, f1); |
127 |
} |
128 |
|
129 |
public static class MyRepo extends Repository { |
130 |
static FileSystem sysfs; |
131 |
public MyRepo () { |
132 |
super(sysfs = FileUtil.createMemoryFileSystem()); |
133 |
try { |
134 |
FileObject fld = sysfs.getRoot().createFolder("folder"); |
135 |
fld.createData("file.txt"); |
136 |
} catch (IOException ioe) { |
137 |
throw new Error (ioe); |
138 |
} |
139 |
} |
140 |
} |
64 |
} |
141 |
} |