Added
Link Here
|
1 |
/* |
2 |
* PathLookupProviderTest.java |
3 |
* |
4 |
* Created on March 20, 2007, 10:58 PM |
5 |
* |
6 |
* To change this template, choose Tools | Template Manager |
7 |
* and open the template in the editor. |
8 |
*/ |
9 |
|
10 |
package org.openide.loaders; |
11 |
|
12 |
import java.io.IOException; |
13 |
import java.util.Collection; |
14 |
import org.netbeans.junit.MockServices; |
15 |
import org.netbeans.junit.NbTestCase; |
16 |
import org.openide.filesystems.FileObject; |
17 |
import org.openide.filesystems.FileSystem; |
18 |
import org.openide.filesystems.FileUtil; |
19 |
import org.openide.filesystems.Repository; |
20 |
import org.openide.loaders.PathLookupProviderTest.O; |
21 |
import org.openide.util.Lookup; |
22 |
import org.openide.util.lookup.Lookups; |
23 |
|
24 |
/** |
25 |
* This is a class |
26 |
* |
27 |
* @author Tim Boudreau |
28 |
*/ |
29 |
public class PathLookupProviderTest extends NbTestCase { |
30 |
|
31 |
/** Creates a new instance of PathLookupProviderTest */ |
32 |
public PathLookupProviderTest(String name) { |
33 |
super (name); |
34 |
} |
35 |
|
36 |
FileObject data; |
37 |
static boolean objCreated = false; |
38 |
public void setUp() throws IOException { |
39 |
objCreated = false; |
40 |
MockServices.setServices (MyRepo.class); |
41 |
FileObject fld = FileUtil.getConfigurationFolder("somewhere/or/other", true); |
42 |
assertNotNull (fld); |
43 |
data = fld.createData ("org-openide-loaders-PathLookupProviderTest$O.instance"); |
44 |
} |
45 |
|
46 |
public void testInstanceIsFound() { |
47 |
System.out.println("testInstanceIsFound"); |
48 |
Lookup lkp = Lookups.forPath ("somewhere/or/other"); |
49 |
assertNotNull (lkp); |
50 |
assertNotSame (Lookup.EMPTY, lkp); |
51 |
Collection <? extends O> c = lkp.lookupAll(O.class); |
52 |
assertTrue (objCreated); |
53 |
assertFalse (c.isEmpty()); |
54 |
} |
55 |
|
56 |
public static class MyRepo extends Repository { |
57 |
static FileSystem sysfs; |
58 |
public MyRepo () { |
59 |
super(sysfs = FileUtil.createMemoryFileSystem()); |
60 |
} |
61 |
} |
62 |
|
63 |
|
64 |
static char ch = 'A'; |
65 |
public static final class O { |
66 |
private final String s; |
67 |
public O () { |
68 |
this ("" + (ch++)); |
69 |
} |
70 |
|
71 |
O (String s) { |
72 |
this.s = s; |
73 |
objCreated = true; |
74 |
} |
75 |
|
76 |
public String toString() { |
77 |
return s; |
78 |
} |
79 |
} |
80 |
|
81 |
} |