Open Test-File as Document to test CompletionProvider
"deveth0" <[email protected]> Sun, 01 May 2016 13:06:04 +0000
| Newsgroups | gmane.comp.java.netbeans.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I'm developer for the Netbeans Sightly Extension (http://wcm.io/tooling/netbeans/sightly/) and currently try to cleanup the code and add additional tests.
To test my CompletionProvider classes I'd like to open a local file as javax.swing.text.Document and pass it to my CompletionProvider.
My browsing through the Netbeans Source-Code brought up a solution that should work in my eyes but fails (see below). Is there any chance for me to use local test-files inside my unit-tests through this workflow or am I completely wrong here?
I'd appreciate any suggestions/hints.
Thanks a lot!
Alex
[code]
public Document getTestDocument(String filename) throws IOException, BadLocationException {
File file = new File(getClass().getResource("/" + filename).getPath());
return openDocument(FileUtil.createData(file));
}
private Document openDocument(FileObject f) {
try {
DataObject dataObject = DataObject.find(f);
EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
return ec.openDocument();
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
[code]
[code]
java.lang.ExceptionInInitializerError: null
at org.netbeans.api.project.ProjectManager.<init>(ProjectManager.java:76)
at org.netbeans.api.project.ProjectManager.<clinit>(ProjectManager.java:70)
at org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation.getOwner(SimpleFileOwnerQueryImplementation.java:161)
at org.netbeans.api.project.FileOwnerQuery.getOwner(FileOwnerQuery.java:114)
at org.netbeans.modules.projectapi.ProjectFileEncodingQueryImplementation.getEncoding(ProjectFileEncodingQueryImplementation.java:72)
at org.netbeans.api.queries.FileEncodingQuery.getEncoding(FileEncodingQuery.java:96)
at org.openide.text.DataEditorSupport.openDocument(DataEditorSupport.java:584)
at io.wcm.tooling.netbeans.sightly.completion.BaseTest.openDocument(BaseTest.java:69)
[code][/code]