6

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?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Mike
  • 19,267
  • 11
  • 56
  • 72

1 Answers1

10

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);
}});
wcmatthysen
  • 445
  • 4
  • 19
Michael Barker
  • 14,153
  • 4
  • 48
  • 55