samedi 5 avril 2014

jmock simplest case doesn't work


Vote count:

0




That's my JMock test:



@Test
public void testRunModuleOK() {
App instance = getInstanceApp(window,logger);
Mockery context = new JUnit4Mockery();
final Modulable m = context.mock(Modulable.class);

context.checking(new Expectations() {{
oneOf(m).init(logger);
oneOf(m).start();
}});

instance.runModule(m);

}


And that's runModule:



void runModule(Modulable module) {
if(module == null)
throw new NullPointerException("Module is null");
module.init(mainLogger);
runningModules.add(module);
module.start();
}


I want my test to make sure that init() and start() is always called once. Unfortunately, when I comment out module.init and module.start in runModule, test still passes. I used println to make sure the code and the test is called. Strangely, when I call init (or start) twice, I get failure as expected. Also, when I comment out 'oneOf...' from expectations, I also get failure. Why does the test passes if module.init and / or module.start is not called in runModule? Thanks.



asked 50 secs ago






Aucun commentaire:

Enregistrer un commentaire