Re: Open Test-File as Document to test CompletionProvider
Benno Markiewicz <[email protected]> Mon, 2 May 2016 20:26:58 +0200
| Newsgroups | gmane.comp.java.netbeans.devel |
|---|---|
| Message-ID | <CAA_aP4gqxvzZvJ4y5ofdgyK=yKoE2_5AC3iVAauKjVeT9OFzFA@mail.gmail.com> |
I guess you are missing a dependency or a registration of projectmanager implementation. Have a look how other projecttypes are tested. F.e. https://github.com/radimk/nbgradle/blob/master/core/src/test/java/org/nbgradle/netbeans/project/GradleProjectFactoryTest.java With kind regards, markiewb 2016-05-01 15:06 GMT+02:00 deveth0 <[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] > > > > >