Lines 50-58
Link Here
|
50 |
import java.util.Set; |
50 |
import java.util.Set; |
51 |
import java.util.logging.Level; |
51 |
import java.util.logging.Level; |
52 |
import org.netbeans.junit.Log; |
52 |
import org.netbeans.junit.Log; |
|
|
53 |
import org.netbeans.junit.MockServices; |
53 |
import org.netbeans.junit.NbTestCase; |
54 |
import org.netbeans.junit.NbTestCase; |
54 |
import org.netbeans.modules.projectapi.TimedWeakReference; |
55 |
import org.netbeans.modules.projectapi.TimedWeakReference; |
|
|
56 |
import org.netbeans.spi.project.ProjectFactory; |
57 |
import org.netbeans.spi.project.ProjectState; |
55 |
import org.openide.filesystems.FileObject; |
58 |
import org.openide.filesystems.FileObject; |
|
|
59 |
import org.openide.util.Lookup; |
56 |
import org.openide.util.test.MockLookup; |
60 |
import org.openide.util.test.MockLookup; |
57 |
|
61 |
|
58 |
/* XXX tests needed: |
62 |
/* XXX tests needed: |
Lines 174-179
Link Here
|
174 |
assertNotNull("Can load goodproject yet again", p); |
178 |
assertNotNull("Can load goodproject yet again", p); |
175 |
assertEquals("Correct project directory set again", goodproject, p.getProjectDirectory()); |
179 |
assertEquals("Correct project directory set again", goodproject, p.getProjectDirectory()); |
176 |
assertEquals("ProjectFactory was called only once on new goodproject folder object", 1, TestUtil.projectLoadCount(goodproject)); |
180 |
assertEquals("ProjectFactory was called only once on new goodproject folder object", 1, TestUtil.projectLoadCount(goodproject)); |
|
|
181 |
} |
182 |
|
183 |
|
184 |
public static final class NonProjectFactory implements ProjectFactory { |
185 |
static FileObject recognize; |
186 |
|
187 |
public boolean isProject(FileObject projectDirectory) { |
188 |
return projectDirectory.equals(recognize); |
189 |
} |
190 |
public Project loadProject(FileObject projectDirectory, ProjectState state) throws IOException { |
191 |
if (isProject(projectDirectory)) { |
192 |
recognize = null; |
193 |
return new MyNonProject(projectDirectory); |
194 |
} |
195 |
return null; |
196 |
} |
197 |
public void saveProject(Project project) throws IOException, ClassCastException { |
198 |
} |
199 |
} |
200 |
static final class MyNonProject implements Project { |
201 |
FileObject dir; |
202 |
|
203 |
public MyNonProject(FileObject dir) { |
204 |
this.dir = dir; |
205 |
} |
206 |
|
207 |
public FileObject getProjectDirectory() { |
208 |
return dir; |
209 |
} |
210 |
|
211 |
public Lookup getLookup() { |
212 |
return Lookup.EMPTY; |
213 |
} |
214 |
} |
215 |
|
216 |
public void testProjectCanBeGCedWhenItContainsNameNonProject() throws Exception { |
217 |
MockLookup.setInstances(new NonProjectFactory(), TestUtil.testProjectFactory()); |
218 |
Project prev = null; |
219 |
NonProjectFactory.recognize = goodproject; |
220 |
prev = pm.findProject(goodproject); |
221 |
assertNotNull("Project recognized", prev); |
222 |
assertEquals(MyNonProject.class, prev.getClass()); |
223 |
pm.clearNonProjectCache(); |
224 |
Project p = pm.findProject(goodproject); |
225 |
assertNotNull("Should have recognized goodproject", p); |
226 |
assertEquals("ProjectFactory was called once so far on goodproject", 1, TestUtil.projectLoadCount(goodproject)); |
227 |
|
228 |
Reference<?> weak = new WeakReference<Object>(prev); |
229 |
prev = null; |
230 |
assertGC("NonProject can disappear", weak); |
231 |
|
232 |
// continue the normal test |
233 |
p = null; |
234 |
testFindProjectGC(); |
177 |
} |
235 |
} |
178 |
|
236 |
|
179 |
public void testFindProjectDoesNotCacheLoadErrors() throws Exception { |
237 |
public void testFindProjectDoesNotCacheLoadErrors() throws Exception { |