Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMock Allow Other Method Calls

I'm using JMock to test the behavior of a class using an object. I want to test that the method a() is called. However, b() and c() also are called on the object too. Therefore if my expectations expect a(), it must also expect b() and c() to make the test pass. Is there a way to test only for a certain method, and allow anything else?

like image 376
Mike Avatar asked Mar 20 '11 18:03

Mike


1 Answers

Expect a() allow only methods b() & c()

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

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

Expect a() allow all other methods.

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

    allowing(mockObject);
}});
like image 95
Michael Barker Avatar answered Oct 23 '22 09:10

Michael Barker