8

I dont think minInvocation or maxInvocation is equivalent to times() in Mockito. Is there?

Please see this questions: Major difference between: Mockito and JMockIt

which has not been answered yet by anyone.

Edit

I found the answer myself: Adding it here for others who need this answered:

The solution is to use DynamicPartialMocking and pass the object to the constructor of the Expectations or NonStrictExpectations and not call any function on that object.

Then in the Verifications section, call any function on the object for which you want to measure the number of invocations and set times = the value you want

new NonStrictExpectations(Foo.class, Bar.class, zooObj)
{
    {
        // don't call zooObj.method1() here
        // Otherwise it will get stubbed out
    }
};


new Verifications()
{
    {
        zooObj.method1(); times = N;
    }
};
Community
  • 1
  • 1
user855
  • 19,048
  • 38
  • 98
  • 162
  • 1
    could you add the answer as an answer (and accept it) -- instead of an edit to the question? This way, it'll not show in the 'unanswered' bucket? – Adam Wagner Oct 15 '11 at 18:14

1 Answers1

3

I found the answer myself: Adding it here for others who need this answered:

The solution is to use DynamicPartialMocking and pass the object to the constructor of the Expectations or NonStrictExpectations and not call any function on that object.

Then in the Verifications section, call any function on the object for which you want to measure the number of invocations and set times = the value you want

new NonStrictExpectations(Foo.class, Bar.class, zooObj)
{
    {
        // don't call zooObj.method1() here
        // Otherwise it will get stubbed out
    }
};


new Verifications()
{
    {
        zooObj.method1(); times = N;
    }
};
Jeff Olson
  • 6,323
  • 2
  • 22
  • 26
user855
  • 19,048
  • 38
  • 98
  • 162
  • In most cases, you don't need to use partial mocking. Instead, use "regular" mocking by declaring a mock field or mock parameter using one of the `@Mocked`, `@NonStrict`, etc. mocking annotations. – Rogério Feb 06 '13 at 13:17