| // |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // |
| = UsingFileSystemsMasterfs |
| :jbake-type: wiki |
| :jbake-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| :syntax: true |
| :description: APITest SIGTest NetBeans |
| :icons: font |
| :source-highlighter: pygments |
| :toc: left |
| :toc-title: |
| :experimental: |
| |
| You can use the Filesystems API freely in unit tests. For example: |
| |
| [source, java] |
| ---- |
| 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`: |
| |
| [source, 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> |
| --> |
| ---- |
| |
| Changes made using the Filesystems API should fire change events synchronously, which is helpful for testing code which listens for file changes. |