JMock Allow Other Method Calls

I use JMock to test the behavior of a class using an object. I want to check if a method is called a(). However, b()and are c()also called on the object. Therefore, if my expectations are expected a(), it is also to be expected b(), and c()to pass the test. Is there a way to check only for a specific method and allow anything else?

+5
source share
1 answer

Expect a()to allow only methods b()andc()

mockery.checking(new Expectations() {{
    one(mockObject).a();

    allowing(mockObject).b();
    allowing(mockObject).c();
}});

Expect a()to allow all other methods.

mockery.checking(new Expectations() {{
    one(mockObject).a();

    allowing(mockObject);
}});
+9
source

All Articles