Simple Problem with ProjectManager.findProject() being null in a unit-test

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Simple Problem with ProjectManager.findProject() being null in a unit-test

Thomas Sobieroy

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);       

    }

}

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simple Problem with ProjectManager.findProject() being null in a unit-test

Geertjan Wielenga-3


I don't know the answer, but this could help:

http://alvinalexander.com/java/jwarehouse/netbeans-src/ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/TestBase.java.shtml

Gj


On 4-6-2017 11:13, Thomas Sobieroy wrote:

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);       

    }

}

 


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simple Problem with ProjectManager.findProject() being null in a unit-test

Thomas Sobieroy

Hey Geertjan,

 

Thanks a lot, normalizing the file did the trick.

 

Best regards

Thomas

 

Von: geertjan wielenga [mailto:[hidden email]]
Gesendet: Sonntag, 4. Juni 2017 12:01
An: [hidden email]
Betreff: [platform-dev] Re: Simple Problem with ProjectManager.findProject() being null in a unit-test

 

 

I don't know the answer, but this could help:

http://alvinalexander.com/java/jwarehouse/netbeans-src/ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/TestBase.java.shtml

Gj

 

On 4-6-2017 11:13, Thomas Sobieroy wrote:

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);       

    }

}

 

 

Loading...