Hi Oscar,

That sample looks *almost* correct.  JMockActions.returnEach is a custom
implementation of the JMock Action API that I wrote for some purpose or
other (a method that returns a different value each time it is called); but
normally one would use the built-in action implementations, usually either
"returnValue(...)" or "throwException(...)".

Thus:

        // given
        context.checking(new Expectations() {
            {
                one([DOMAIN SERVICE]).locale();
                will(returnValue(new Locale("en")));
            }
        });

Are you certain that [DOMAIN SERVICE] is a mock, though?  the
IntegrationTestAbstract will usually return real service implementations?

(I was about to go on to say say that you could override
IntegrationTestAbstract#getService(...) to return a mock for the service
you want, but on second thoughts I don't think that would work, because the
actual system under test would be using a real implementation of the
service)

If you are still struggling with JMock, I have a TDD training course that
covers it, happy to send you it off-list.

Cheers
Dan




On 18 June 2014 18:43, GESCONSULTOR - Óscar Bou <[email protected]>
wrote:

> Hi to all.
>
> I have an Integration Test where I want to mock the resulting value of a
> service's method.
>
> I have no experience with JMock and seems quite different from mockito.
>
> I see the "context" property defined on IntegrationTestAbstract, but not
> sure about how to best specify that whenever I invoke that service method,
> the result value should be "x".
>
> I've looked at the samples at [1], but not sure about how to specify
> something like:
>
>         // given
>         // final UserAccount userAccount = this.service(UserAccount.class);
>         this.context.checking(new Expectations() {
>             {
>                 this.one([DOMAIN SERVICE]).locale();
>                 this.will(JMockActions.returnEach(new Locale("en")));
>             }
>         });
>
>
> Any help, please?
>
> Thanks,
>
> Oscar
>
>
>

Reply via email to