UsingFileSystemsMasterfs

You can use the Filesystems API freely in unit tests. For example:

private FileObject d;
protected void setUp() throws Exception {
    clearWorkDir();
    d = FileUtil.toFileObject(getWorkDir());
    assertNotNull(d);
}

If you try to run the above code, by default you will get an assertion error in setUp: toFileObject returns null. This is because you need the Master Filesystem module available in order to translate Files into FileObjects. Add to your project.xml:

<!-- if not already there:
            <test-dependencies>
                <test-type>
                    <name>unit</name>
-->
                    <test-dependency>
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
                    </test-dependency>
<!-- if not already there:
                </test-type>
            </test-dependencies>
-->

Note: the above is for NetBeans 6.0, or 5.5 with the forthcoming 5.5 Update 1 of the module development support. For earlier releases you must add to project.properties:

test.unit.run.cp.extra=\
    ${openide/masterfs.dir}/modules/org-netbeans-modules-masterfs.jar

The openide/masterfs.dir property will only be defined for modules in the netbeans.org source tree. For a platform application using NetBeans 5.5 or earlier, or for tests based on XTest (regardless of what version of NetBeans you are using), you will need to define the path differently.

Changes made using the Filesystems API should fire change events synchronously, which is helpful for testing code which listens for file changes.

Currently (bug #84501) you also need the org.netbeans.core.startup module if you want FileUtil.getArchiveRoot and some related functionality to work.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo