JUnit and Netbeans. Injecting in objects in the default Lookup
If you need to unit test classes in a netbeans module and the classes use the Lookup.getDefault() to “lookup” things that you want to mock you probably wonder how you can place the mock objects in the default Lookup Adding objects to the Netbeans’s default Lookup is relatively simple. Here is the answer: Replace the `Lookup` instance returned by the `Lookup.getDefault()` by defining a new entry in `META-INF/services`. It’s just a matter of adding a file named org.openide.util.Lookup$Provider in the META-INF/services folder inside your Unit Test source folder. That file should contain the fully qualified class name of your own Lookup.Provider implementation. In my case the file contain just the string com.rubenlaguna.en4j.searchlucene.NoteFinderLuceneImplTest because the test class itself implements Lookup.Provider. ...