Re: Write to disk in Platform based JUnit tests
Johannes Wahle <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[email protected]> |
FileUtil.getConfigRoot() returns a FileObject in a virtual file system,
by creating a child of this virtual folder, you are never going to get a
file/folder on disc.
I'm not quite sure, what you need to do to achieve that.
My guess would be to either remove the call to FileUtil.getConfigRoot()
from the class that is tested, or get a partially initialized module
environment.
You might want to have a look at the NbJUnit module and the
NbModuleSuite class for that matter.
On 02.12.2015 12:56, mhaslinger wrote:
> I am using createData(). But with the other parameter set
> Here some code parts which I use:
>
>
> Code:
>
> FileObject fo = FileUtil.getConfigRoot().createData(FILENAME, EXTENSION);
> lock = fo.lock();
> try (PrintWriter to = new PrintWriter(fo.getOutputStream(lock))) {
> to.println("some stuff");
> to.flush();
> } finally {
> lock.releaseLock();
> }
>
>
>
>
> This creates the file an later I need to get the URL but as "file://"
>
>
> Code:
>
> FileObject fo = FileUtil.getConfigRoot().getFileObject(FILENAME, EXTENSION); //this work
> URI uri = Utilities.toURI(FileUtil.toFile(fo)).toString(); //this will be processed by external code than - it Fails as toFile(..) creates null
>
>
>
>
> We are using ant for building which should not be any difference to the code itself.
>
>
>
>