0

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();
    }
}
ᴇʟᴇvᴀтᴇ
  • 12,285
  • 4
  • 43
  • 66
  • [This answer](http://stackoverflow.com/a/5370462/474189) seems to suggest it's quite possible and describes a solution exactly like you are trying. Can you post a minimal example that exhibits this behaviour? You could also try my preferred framework, Mockito, whose default behaviour is to allow all method calls :-) – Duncan Jones May 16 '14 at 13:26
  • Hmm, just wrote a little tester and it looks like I'm doing something else wrong. Thanks Duncan. – ᴇʟᴇvᴀтᴇ May 16 '14 at 13:30
  • Ahhh, the power of the minimal example :-) Good luck bug hunting. – Duncan Jones May 16 '14 at 13:31

0 Answers0