In jMock, is it possible to expect oneOf()
some method while allowing()
all other methods.
When I try to do this, the allowing()
seems to override the oneOf()
expectation and my test passes whether or not the method was called.
I only want the test to pass if the oneOf()
method was called. I don't want to have to explicitly say allowing()
on each method that I don't want to be called because that will clutter up the test.
UPDATE: I tried to write a little example to capture the essence of the problem and it worked, so it looks like I must have done something else wrong.
public class ExampleTest {
@Rule public JUnitRuleMockery context = new JUnitRuleMockery();
interface Callback {
void method1();
void method2();
}
@Test
public void x() {
final Callback callback = context.mock(Callback.class);
context.checking(new Expectations(){{
oneOf(callback).method1();
allowing(callback);
}});
// callback.method1();
callback.method2();
}
}