Simple Problem with ProjectManager.findProject() being null in a unit-test
"Thomas Sobieroy" <[email protected]> Sun, 4 Jun 2017 11:13:02 +0200
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Guys,
Quick Question: I’m using NbTestCase and I want to do something with projects.
Masterfs is set up correctly, such that FileObject d is not null. But if I try to find
a Project with the ProjectManager.getDefault().findProject(d) the result is null.
If I use the same code without unit-testing it, it works, but if I run it in testing
Project remains null. Am I missing something out? Do I have to register something?
I simply want to open and close a project in unit-test.
Also I read the faq and documentation. This can only be a minor thing, but I somehow can’t get It to work.
Best regards
Thomas
import java.io.File;
import junit.framework.Test;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.junit.NbModuleSuite;
import org.netbeans.junit.NbTestCase;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
public class ProjectTests extends NbTestCase {
private final static String projectPath = "C:\\Path\\To\\Project";
public ProjectTests(String name) {
super(name);
}
/**
* @brief checks if loading of files is o.k, if not the masterfs dependency
* is missing in unit test library
* @throws Exception
*/
public void testSetup() throws Exception {
FileObject d = FileUtil.toFileObject(new File(projectPath));
//here we check if masterfs is loaded
assertNotNull(d);
ProjectManager PM = ProjectManager.getDefault();
//try finding project
org.netbeans.api.project.Project project = PM.findProject(d);
//assert that is loadable
assertNotNull(project);
}
}