Thanks for the hints ... of course MockServices is exactly what I want, and I had read about it before but ... it slipped my mind.
I do have a problem with this though ... I can't get it to work in my UI Functional Tests
here is the basic code ...
Code:
public class MockTest extends JellyTestCase {
public MockTest(String name) {
super(name);
}
/**
* Without this method the test will work, But I don't get a UI
*/
public static Test suite() {
NbModuleSuite.Configuration testConfig = NbModuleSuite.createConfiguration(MockTest.class);
testConfig.clusters(".*").enableModules(".*");
testConfig.gui(true);
return NbModuleSuite.create(testConfig);
}
@Override
public void setUp() {
MockServices.setServices(Mock.class);
}
public void testIt(){
BulletinService stuff = Lookup.getDefault().lookup(BulletinService.class);
assertEquals(Mock.class, stuff.getClass());
}
public static class Mock implements BulletinService {
@Override
public BulletinResult submitBulletin(Bulletin arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
}
Its having the suite method that is breaking it (but the suite method is required to setup the UI testing framework)
What happens is I get this exception stack ...
Code:
Testcase: testIt(com.metservice.castlepoint.maps.MockTest): FAILED
expected:<class com.metservice.castlepoint.maps.MockTest$Mock> but was:<class com.metservice.castlepoint.maps.MockTest$Mock>
junit.framework.AssertionFailedError: expected:<class com.metservice.castlepoint.maps.MockTest$Mock> but was:<class com.metservice.castlepoint.maps.MockTest$Mock>
at org.netbeans.junit.MockServices$ServiceClassLoader.<init>(MockServices.java:146)
at org.netbeans.junit.MockServices.setServices(MockServices.java:91)
at com.metservice.castlepoint.maps.MockTest.setUp(MockTest.java:40)
at org.netbeans.junit.NbTestCase.runBare(NbTestCase.java:328)
at org.netbeans.jellytools.JellyTestCase.runBare(JellyTestCase.java:147)
at org.netbeans.junit.NbTestCase.run(NbTestCase.java:213)
at org.netbeans.junit.NbModuleSuite$S.runInRuntimeContainer(NbModuleSuite.java:782)
at org.netbeans.junit.NbModuleSuite$S.run(NbModuleSuite.java:570)
I can understand some of it, I have seen that kind of assertion fail before when one class is loaded from different class loaders, equal will then fail... and can see in the source (well the source I could find, must be an old version) in the MockServices class that some classloader magic is happening
But I have no idea how to fix things in this case ... any ideas floating around?
Cheers
Steve